Gemini Files & Cache
Upload Gemini file
Uploads bytes or starts a resumable upload.
Uploads bytes or starts a resumable upload. For resumable start, send metadata and read X-Goog-Upload-URL. Continue only at that returned URL. The upload URL grants access to that upload, expires after one hour, and must be kept private.
Which upload path to use
Choose one of these paths, and do not mix them in one request:
| Path | What you send | When to use it |
|---|---|---|
| Inline data URL | data:image/png;base64,<BASE64> as the OpenAI-compatible image_url.url value, for example {"type":"image_url","image_url":{"url":"data:image/png;base64,..."}} | The file is small, you need no reusable file URI, and your client sends the OpenAI content shape |
| Inline bytes | The file's raw Base64, with no data: prefix, in contents[].parts[].inlineData.data with its mimeType | The file is small, you need no reusable file URI, and your client sends the Gemini native shape |
| Public URL | An https URL in contents[].parts[].fileData.fileUri, or as image_url.url in the OpenAI content shape | The bytes are already hosted where TokenLab can fetch them |
| This endpoint | The bytes to POST /upload/v1beta/files with your TokenLab key, then the returned file_uri | You need one file referenced by several requests, or by cached content |
inlineData.data is not a data URL: it takes the Base64 payload on its own. The data:image/png;base64,... form belongs in a field that expects a URL, such as image_url.url.
The SDK upload helper is not available
The Google Gen AI SDK's own upload helper, such as client.files.upload in google-genai or @google/genai, is not served by the TokenLab host and returns 404. Retrying it cannot succeed. Call POST /upload/v1beta/files yourself with your TokenLab key and use the returned file_uri, or send inline bytes or a public URL as described above.
See Gemini Files and cached content for the SDK client setup, the resumable session rules, and the full operation list.
curl -X POST "https://example.com/upload/v1beta/files" \ -H "Content-Type: application/json" \ -d '{}'{ "file": { "name": "string", "displayName": "string", "mimeType": "string", "sizeBytes": "string", "uri": "string", "state": "string", "createTime": "2019-08-24T14:15:22Z", "updateTime": "2019-08-24T14:15:22Z", "expirationTime": "2019-08-24T14:15:22Z", "error": {} }}API Key authentication. Create or manage API keys in Dashboard > API > API Keys.
In: header
Query Parameters
API key alternative to Bearer or x-goog-api-key.
Headers
Reuse the same key and request body when recovering a create response. A different body with the same key returns a conflict.
Upload protocol such as resumable.
Upload command such as start or upload, finalize.
Expected file byte length when starting a resumable upload.
File MIME type when starting a resumable upload.
Gemini file metadata request. Supported fields and values are validated by the service. File bytes are uploaded through /upload/v1beta/files.
Response
application/json
application/json
application/json
application/json
application/json
application/json
application/json
application/json
application/json