generateContent and streamGenerateContent endpoints.
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 are already using the Google Gemini SDK or are familiar with the official API format, you can use this API directly without modifying the request format.
Current Support Scope
The interface accepts text, image, video, and audio inputs (inlineData or fileData), thinking configuration, and custom function declarations. Native fields such as audio output, built-in tools, and explicit context caching do not yet have guaranteed unified availability; please refer to the actual response of the specific model.
When submitting audio and other files using fileData.fileUri, please ensure that the file can be accessed directly via HTTPS, does not depend on a login state, and that the validity period of the signed link covers the entire request processing time. Non-streaming audio analysis returns results only after the model has finished processing, which may exceed 90 seconds; clients should set a sufficiently long total timeout according to file size and business scenarios, to avoid disconnecting while the server is still processing.
Application Process
Before using the Gemini Generate Content API, please first visit the Gemini Generate Content API page and click the “Get” button to obtain the credentials required for requests. If you have not yet logged in or registered, you will be automatically redirected to the login page. The first application includes free credits.Basic Usage
Non-Streaming
Send a POST request to/v1beta/models/{model}:generateContent:
Note: The flash models in thegemini-3.xseries are thinking models and will consume reasoning tokens first; please setgenerationConfig.maxOutputTokensto above 512, otherwise only empty content may be returned.
usageMetadata are billed according to native Gemini semantics:
promptTokenCountincludescachedContentTokenCount; cache-hit portions are calculated at the cache read price and will not be counted again as regular input.promptTokensDetailsandcacheTokensDetailsare normalized intotext_tokens,image_tokens,video_tokens,audio_tokens, and their correspondingcached_*details underusage.prompt_tokens_details. These values are included inprompt_tokensandcached_tokensrespectively; different modalities are recalculated only at their respective prices and will not be billed repeatedly.- Both
candidatesTokenCountandthoughtsTokenCountare calculated at the output token price. toolUsePromptTokenCountis an independent tool input token count and is calculated at the input token price.
usage object. Across model protocols, read the cost of the current call uniformly from usage.cost. cost is an optional cost preview; when price previews are temporarily unavailable, the model response will still return normally but may not include this field. The final bill is subject to usage records.
Streaming
Send a POST request to/v1beta/models/{model}:streamGenerateContent?alt=sse:
usageMetadata and normalized usage, while the cost remains 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
Advanced Features
System Instructions
Generation Configuration
JSON Mode
Thinking Mode (Thinking)
Models that support thinking capabilities (such as gemini-2.5-flash and gemini-2.5-pro) can enable thinking mode:Function Calling
Multi-turn Conversation
Image Understanding
Safety Settings
Content filtering can be controlled throughsafetySettings:

