The native Gemini API consistently uses /v1/models/{model}:... paths and preserves Gemini request and response semantics.
https://api.tokensmarket.aiPOST /v1/models/{model}:generateContentThe endpoint remains fixed. Use the parameter documentation on this page to replace the model ID and request data.
${base_url}/v1/models/{model}:generateContent${base_url}/v1/models/{model}:streamGenerateContent${base_url}/v1/models/{model}:embedContent${base_url}/v1/models/{model}:batchEmbedContentsChoose one Gemini-compatible authentication method.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
Authorization | string | No | — | Bearer API Key. |
x-goog-api-key | string | No | — | Gemini API Key header. |
key | string | No | — | URL query parameter ?key=<API_KEY>. |
Both generation endpoints use contents. Stream Generate Content enables native SSE and supports Session routing.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
contents | Content[] | Yes | — | A non-empty Gemini content/part array. |
systemInstruction | Content | No | — | System content. |
generationConfig | object | No | — | Generation configuration. |
tools | array | No | — | Tool declarations. |
session_id / extra_body.session_id / X-Session-Id | string | No | — | Session routing for generation endpoints, read in this precedence order. Options / constraints: Maximum 256 characters. |
extra_body.provider | object | No | — | Optional provider routing configuration. |
Embed Content uses one content and does not expose Session routing.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
content | Content | Yes | — | One Gemini Content to embed. |
taskType | string | No | — | Embedding task type when supported by the model. |
outputDimensionality | integer | No | — | Output dimensionality when supported by the model. |
extra_body.provider | object | No | — | Optional provider routing configuration. |
requests[] must not be empty. The model in the URL is written to the root request and every child request.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
requests[] | EmbedContentRequest[] | Yes | — | Non-empty array of embedding child requests. |
requests[].content | Content | Yes | — | Embedding content for each child request. |
extra_body.provider | object | No | — | Optional provider routing configuration. |
The following fields are HTTP response headers, not JSON, SSE event, or binary response body fields. They are not guaranteed when a network failure prevents the request from reaching the gateway.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
X-Client-Request-Id | string | No | — | Echoed when supplied by the caller; the gateway does not generate it automatically when omitted. |
X-Upstream-Request-Id | string | No | — | Usually used for gateway request tracing; it does not represent the provider's original request ID. |
The error body follows the selected protocol. HTTP 400 means invalid_request, HTTP 402 means insufficient available balance or quota, and HTTP 429 means rate limiting.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
error.code | string | No | — | Machine-readable error code defined by the protocol. |
error.message | string | No | — | Human-readable error description. |
A native Gemini stream ends after the final response that includes finishReason and usageMetadata; it does not append data: [DONE]. Clients aggregate content by candidate and part, and treat an unexpected EOF as incomplete.
embedContent returns embedding.values and batchEmbedContents returns embeddings[]; neither embedding endpoint streams.
The examples use placeholders. Replace them with a currently available model ID from the model details page, and keep your API Key in a server-side environment variable.
curl -X POST "https://api.tokensmarket.ai/v1/models/<MODEL_ID>:generateContent" \
-H "x-goog-api-key: $TOKEN_MARKET_API_KEY" \
-H "Content-Type: application/json" \
-d '{"contents":[{"role":"user","parts":[{"text":"Explain caching."}]}],"extra_body":{"session_id":"conversation-<UUID>","provider":{"sort":["latency"]}}}'