generateContent and streamGenerateContent endpoints.
New integrations use the stable /v1 version by default. Existing clients can continue to call both methods using /v1beta, with the same platform credentials, authorization, and billing rules. For streaming calls, add ?alt=sse after the method name.
Differences from the Chat Completions API
The Gemini Generate Content API uses Google’s official native request format (thecontents field) rather than the OpenAI-compatible format (the messages field). If you already use the Google Gemini SDK or are familiar with the official API format, you can use this API directly without changing the request format.
Current Support
The API accepts text, image, video, and audio inputs (inlineData or fileData), thinking configuration, and custom function declarations. Availability of native fields such as audio output, built-in tools, and explicit context caching is not yet guaranteed across the board; refer to the actual response from each model.
When submitting audio or other files using fileData.fileUri, ensure that the files are directly accessible over HTTPS without requiring a logged-in session, and that signed links remain valid for the entire request processing time. Non-streaming audio analysis returns results only after the model has completed processing, which may take more than 90 seconds; clients should set a sufficiently long total timeout based on file size and the use case to avoid disconnecting while the server is still processing.
Application Process
Log in to the application list, open Universal Application, and click the copy button to the right of the API KEY field. Store the key on the server for use asyour_token_here in the examples below.
Gemini Generate Content API Parameters and Online Testing
Basic Usage
Non-Streaming
Send a POST request to/v1/models/{model}:generateContent:
Tip: The flash models in thegemini-3.xseries are thinking models and consume reasoning tokens first; setgenerationConfig.maxOutputTokensabove 512, or the response may contain only empty content.
usageMetadata are billed according to native Gemini semantics:
promptTokenCountincludescachedContentTokenCount; cache hits are billed at the cache-read price and are not counted again as regular input.promptTokensDetailsandcacheTokensDetailsare normalized intotext_tokens,image_tokens,video_tokens,audio_tokens, and the correspondingcached_*details underusage.prompt_tokens_details. These values are included inprompt_tokensandcached_tokens, respectively; different modalities are recalculated only at their respective prices and are not billed twice.- Both
candidatesTokenCountandthoughtsTokenCountare billed at the output token price. toolUsePromptTokenCountrepresents separate tool input tokens, billed at the input token price.
usage object, allowing the cost of the call to be read consistently from usage.cost across model protocols. cost is an optional cost preview; when the price preview is temporarily unavailable, the model response will still be returned normally but may omit this field. The final bill is based on usage records.
The generateContent and streamGenerateContent methods for Gemini 4 Argon, Carbon, Hydrogen, and Neon use native API unit prices. Converted at the Credits exchange rate for the largest package, the input, output, and cache-read unit prices are 70% of the corresponding Google Gemini API Standard prices. Thinking tokens count as output, and account usage discounts are calculated separately. Google Gemini API Pricing
Streaming
Send a POST request to/v1/models/{model}:streamGenerateContent?alt=sse:
usageMetadata and the normalized usage, with the cost still located in usage.cost:
data: [DONE]. If the final price preview is temporarily unavailable, usage will still return token usage but will omit cost.
Supported Models
gemini-4-carbon and gemini-4-hydrogen can currently be invoked through Chat Completions; native Generate Content is temporarily unavailable. The official model specifications list text, image, video, audio, and PDF inputs and text output; this does not mean that all input types have been verified on the current platform. After native invocation is restored, submit requests according to the API contract on this page and separately verify the required inputs and parameters. The official long decode output of one million tokens is not included in the current API contract. Both support only implicit caching, and thinking tokens are charged at the output price; the prepared pricing rules use the same input token unit price for all input modalities, and cache hits are charged at the cache read unit price. See the current pricing page for details.
Advanced Features
System Instructions
Generation Configuration
JSON Mode
Internal Thinking and Thought Summaries
The model’s internal thinking and the return of thought summaries to the caller are two independent settings:thinkingBudgetorthinkingLevelcontrols the model’s internal thinking budget or depth; supported fields and values depend on the model.includeThoughtscontrols whether thought summaries are returned and defaults tofalse. When this field is omitted or set tofalse, neither ordinary JSON nor SSE streaming responses return text marked asthought: true; this text is retained only when the Boolean valuetrueis explicitly passed.
includeThoughts, the API passes false by default to generative models that support thinking configuration, avoiding requests for unwanted summaries; values, thinking budgets, and levels explicitly provided by the client are preserved. This field is not automatically added for gemini-2.5-flash-image, which is known not to support thinking configuration, and generation configuration is not added to countTokens requests.
Turning off summaries is not the same as turning off internal thinking and does not guarantee a reduction in internal thinking tokens. If a response still contains unrequested thought text, the ordinary JSON and SSE outputs further filter it while retaining the normal answer, signatures, and actual usage.
When you need to view summaries, explicitly enable them as shown below. If the model does not generate an available summary, there may be no thought text even when enabled:
thoughtSignature is encrypted state required for subsequent turns, not thought summary text, and is not controlled by the includeThoughts switch. A signature may appear on a normal answer, function call, or empty-text Part; when thought text is filtered, the signature and other fields in the same Part are retained, so the response may still contain Parts that carry only a signature and have empty text. When manually maintaining multi-turn history, preserve the order of these Parts and the positions of their signatures; do not move the signatures or merge the Parts.
usageMetadata and usage still record actual usage. Hiding summaries does not reset thoughtsTokenCount to zero, and billing is still calculated based on actual usage and the current pricing rules.
See Google’s official explanation of thinking and thought summaries and thought signature rules.
Function Calling
Multi-Turn Conversations
Image Understanding
Safety Settings
Content filtering can be controlled throughsafetySettings:

