TokenLab

Gemini Files & Cache

Upload Gemini file

Uploads bytes or starts a resumable upload.

POSThttps://api.tokenlab.sh/upload/v1beta/files

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:

PathWhat you sendWhen to use it
Inline data URLdata: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 bytesThe file's raw Base64, with no data: prefix, in contents[].parts[].inlineData.data with its mimeTypeThe file is small, you need no reusable file URI, and your client sends the Gemini native shape
Public URLAn https URL in contents[].parts[].fileData.fileUri, or as image_url.url in the OpenAI content shapeThe bytes are already hosted where TokenLab can fetch them
This endpointThe bytes to POST /upload/v1beta/files with your TokenLab key, then the returned file_uriYou 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": {}  }}

Authorization

AuthorizationBearer <token>

API Key authentication. Create or manage API keys in Dashboard > API > API Keys.

In: header

Query Parameters

key?string

API key alternative to Bearer or x-goog-api-key.

Headers

Idempotency-Key?string

Reuse the same key and request body when recovering a create response. A different body with the same key returns a conflict.

X-Goog-Upload-Protocol?string

Upload protocol such as resumable.

X-Goog-Upload-Command?string

Upload command such as start or upload, finalize.

X-Goog-Upload-Header-Content-Length?string

Expected file byte length when starting a resumable upload.

X-Goog-Upload-Header-Content-Type?string

File MIME type when starting a resumable upload.

Request Body

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