TokenLab

Gemini Native

Stream Generate Content

Streams content generation using Google Gemini API format

POST
/v1beta/models/{model}:streamGenerateContent

SSE version of Gemini generateContent. Events may contain only metadata or intermediate content without finishReason. The stream ends at natural EOF and does not append a [DONE] marker.

Path Parameters

modelstringpathrequired

Model name (e.g., gemini-2.5-pro, gemini-3.5-flash).

Query Parameters

keystringquery

API key (alternative to header authentication).

Authentication

Same as Generate Content: ?key=, x-goog-api-key, or Authorization: Bearer.

Request Body

Same as Generate Content. This includes multimodal parts arrays with structured inline_data image parts for vision requests.

Support for generationConfig.candidateCount, tools, media types, and other optional fields depends on the selected model.

Response

Returns Gemini Server-Sent Events. Metadata-only events, intermediate chunks without finishReason, and natural EOF are valid. The stream does not append Chat Completions' [DONE] sentinel. Each event is a data: line that holds one JSON chunk. The response is always SSE; alt=sse is accepted but not required.

An error before the first event returns a JSON Gemini error with the same codes as Generate Content.

Request

curl -N -X POST "https://api.tokenlab.sh/v1beta/models/gemini-2.5-pro:streamGenerateContent?key=sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "parts": [{"text": "Tell me a story"}]
      }
    ]
  }'

Response

Stream Chunk
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {"text": "Once upon a time"}
        ]
      }
    }
  ]
}

Vision Input Example

Streaming vision requests use the same contents[].parts[] structure as the non-streaming endpoint.

{
  "contents": [
    {
      "role": "user",
      "parts": [
        { "text": "Please describe this image." },
        {
          "inline_data": {
            "mime_type": "image/jpeg",
            "data": "/9j/4AAQSkZJRgABAQ..."
          }
        }
      ]
    }
  ]
}

Authorization

AuthorizationBearer <token>

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

In: header

Path Parameters

model*string

Model name (e.g., gemini-2.5-pro)

Query Parameters

key?string

API key (alternative to header auth)

Headers

X-TokenLab-Delivery-Policy?string

Per-request Delivery policy. Overrides the API key and Workspace defaults. Auto tries TokenLab Verified first and may switch once to Official only before output, request acceptance, or persistent resource creation.

Value in

  • "auto"
  • "verified"
  • "official"

Request Body

application/json

Native Gemini GenerateContent request. ProtoJSON lowerCamelCase and original proto snake_case names are both accepted and preserved, including mixed requests. If both spellings of one field are present, TokenLab does not merge them or choose a local precedence. Unknown fields are forwarded on a best-effort basis.

Response

text/event-stream

application/json

application/json

application/json

application/json

application/json