Skip to main content
POST
Streaming: Replace generateContent with streamGenerateContent in the URL. Keep the request body unchanged; responses arrive in chunks. Append ?alt=sse to request SSE format.
BaseURL: The default BaseURL is https://direct.evolink.ai, which has better support for text models and long-lived connections. https://api.evolink.ai is the primary endpoint for multimodal services and serves as a fallback address for text models.

Long-output continuation (Gemini 4 Argon)

A single gemini-4-argon streaming request returns up to 65,536 tokens; a non-streaming request returns up to 32,768. Both limits include thinking and answer tokens. Use continuation requests for longer output. Input, thinking, and the answer share a 1,048,576-token context window, so cumulative thinking and answer tokens can only use the space remaining after the input. Only the native API supports continuation; the OpenAI-compatible format does not. Set the client read timeout to 1,200 seconds (20 minutes) for long responses. This is a client configuration recommendation, not a guarantee of server request duration. Procedure:
  1. Set generationConfig.maxOutputTokens above the per-request cap: above 65,536 for streaming or 32,768 for non-streaming. The parameter accepts up to 1,048,576, but actual output is still limited by the shared context. This is the cumulative thinking and answer budget across all continuation requests.
  2. When candidates[0].finishReason is CONTINUATION, generation is not finished. The same candidate includes a continuationToken.
  3. Resend the original request with the same contents, systemInstruction, tools, and generationConfig. Add only a top-level continuationToken containing the latest returned token.
  4. Repeat step 3 only while finishReason is CONTINUATION; stop for any other finish reason. STOP means normal completion, and MAX_TOKENS means the cumulative budget is exhausted. Each response contains only newly generated content; concatenate it in order.
  • Do not append partial output to contents or send a new prompt such as “continue”.
  • A request may spend its entire budget on thinking and return empty answer text. Continue if the finish reason is CONTINUATION.
  • MAX_TOKENS may also include a continuationToken. To resume, manually raise maxOutputTokens and resend the original request with the latest token. Keeping the exhausted budget returns 400. See “Resume after budget exhaustion” below.
  • For multi-turn conversations, wait for STOP and then add the combined answer as a single model message to the history.

Examples

First request:
If generation reaches the per-request cap with budget remaining, the response may look like this (only continuation-related fields are shown):
If the previous response ended with CONTINUATION, send the same request again with a top-level continuationToken:
This Python function automatically handles CONTINUATION and returns on completion or budget exhaustion. It preserves the latest token and does not raise the budget automatically on MAX_TOKENS:

Resume after budget exhaustion

This example reuses generate_with_continuation, URL, and HEADERS above. It generates a number list with a small budget, then explicitly raises the total budget from 64 to 2,048. Keep the original contents and other settings unchanged; add the token and raise the budget to resume at the cutoff.
For streaming, read the final chunk containing finishReason: on CONTINUATION, resend the latest token with unchanged settings; on MAX_TOKENS, manually raise the cumulative budget if you want to resume; STOP means normal completion.

Billing and errors

  • Each request is billed separately. Continuation requests count the original input and all previously generated content as input again. Portions that hit implicit caching are billed at the cache rate.
  • Each response’s usageMetadata covers only that request. Add usage across requests for the total. Streaming usage is cumulative within a request: use only the final usageMetadata, rather than adding cumulative values from the same stream.
  • For the native API, the output pre-authorization estimate uses the smaller of maxOutputTokens and 65,536, including for non-streaming requests; input is estimated separately. Non-streaming output is actually capped at 32,768 per request, so budgets above 32,768 may reserve more than an estimate based on the actual per-request cap. Final charges use the response usage.
  • Invalid tokens return 400. A well-formed but invalid token may return Invalid continuation token., while malformed tokens may produce another parameter error. Other models ignore continuationToken.
  • Resuming after MAX_TOKENS with a token but without raising the exhausted maxOutputTokens also returns 400.

Authorizations

Authorization
string
header
required

##All APIs require Bearer Token authentication##

Get API Key:

Visit API Key Management Page to get your API Key

Add to request header:

Path Parameters

model
enum<string>
required

Select the Gemini text model to call:

Available options:
gemini-4-argon,
gemini-3.8-flash,
gemini-3.7-flash,
gemini-3.6-flash,
gemini-3.5-flash,
gemini-3.5-flash-lite,
gemini-3.1-pro-preview,
gemini-3.1-pro-preview-customtools,
gemini-3.1-flash-lite-preview,
gemini-3-pro-preview,
gemini-3-flash-preview,
gemini-2.5-pro,
gemini-2.5-flash,
gemini-2.5-flash-lite
Example:

"gemini-3.6-flash"

Body

application/json
contents
object[]
required

List of conversation contents, supports multi-turn dialogue and multimodal input

Minimum array length: 1
systemInstruction
object

System instruction (optional), mainly text content

tools
object[]

Tools the model may call. Three kinds are supported:

  • functionDeclarations: function calling
  • codeExecution: code execution
  • googleSearch: web search (Google Search grounding). Pass {"googleSearch": {}} (camelCase; snake_case google_search returns 400); available on all Gemini text models. candidates[].groundingMetadata in the response carries the queries and sources; billed per call
Example:
toolConfig
object

Tool calling configuration (optional)

safetySettings
object[]

Safety settings list (optional)

generationConfig
object

Generation configuration parameters (optional)

continuationToken
string

Long-output continuation token (gemini-4-argon only). Put the latest candidates[0].continuationToken at the top level of the request. Preserve the original contents, systemInstruction, and tools; do not append partial output.

  • CONTINUATION: keep every generation setting unchanged and resend the token.
  • MAX_TOKENS: a token may also be returned; manually raise cumulative maxOutputTokens before resuming, leaving other settings unchanged. Keeping the exhausted budget returns 400.
  • Invalid tokens return 400.
  • Other models ignore this field.

See Native API reference, under “Long-output continuation”.

cachedContent
string

Cached content name, in the form cachedContents/{cachedContent}

Response

Content generated successfully

Response format description:

  • When using the generateContent endpoint, returns GenerateContentResponse (returns complete response at once)
  • When using the streamGenerateContent endpoint, returns StreamGenerateContentResponse (streaming response, returns content in chunks)
candidates
object[]

List of candidate responses

promptFeedback
object
usageMetadata
object

Usage statistics

modelVersion
string

Model version

Example:

"gemini-3.6-flash"

responseId
string

Response ID

Example:

"l-LoaPu0BPmo1dkP6ZPHiQc"