The Gemini API supports uploading media files separately from the prompt input, allowing your media to be reused across multiple requests and multiple prompts. For more details, check out the Prompting with media guide.

Creates a File.

Endpoint

  • Upload URI, for media upload requests:
post https://generativelanguage.googleapis.com/upload/v1beta/files
  • Metadata URI, for metadata-only requests:
post https://generativelanguage.googleapis.com/v1beta/files

Request body

The request body contains data with the following structure:

Fields

file object (File)

Optional. Metadata for the file to create.

Example request

Image

Python

Node.js

Go

Shell

Audio

Python

Node.js

Go

Shell

Text

Python

Node.js

Go

Shell

Video

Python

Node.js

Go

Shell

PDF

Python

Go

Response body

Response for media.upload.

If successful, the response body contains data with the following structure:

Fields

file object (File)

Metadata for the created file.

JSON representation
{
  "file": {
    object (File)
  }
}

Method: files.get

Gets the metadata for the given File.

Endpoint

get https://generativelanguage.googleapis.com/v1beta/{name=files/*}

Path parameters

name string

Required. The name of the File to get. Example: files/abc-123 It takes the form files/{file}.

Request body

The request body must be empty.

Example request

Python

Node.js

Go

Shell

Response body

If successful, the response body contains an instance of File.