Generate content
Use the Gemini native API format through CometAPI for text generation, video input, thinking summaries, Google Search grounding, JSON output, and streaming.
gemini-3.8-flash.
x-goog-api-key and Authorization: Bearer headers are supported for authentication.Quick start
To use the Google Gen AI SDK or an HTTP client with CometAPI, configure the base URL and API key:generateContent request shape when changing the base URL.
Send video input
Send video as a content part. Choose the input shape based on where the video is stored:inlineData.mimeType and fileData.fileUri.<base64-encoded-mp4> with the base64 contents of your video:
Configure thinking (reasoning)
UsethinkingConfig.thinkingLevel to guide reasoning depth. The examples below use LOW and MEDIUM.
- Thinking level
- Thinking summaries
LOW:thinkingBudget is a numeric control for compatible models, including Gemini 2.5. Use thinkingLevel in the Gemini 3 examples and do not send both controls. See Google’s thinking guide for model-specific values.Stream responses
UsestreamGenerateContent?alt=sse to receive Server-Sent Events. Each data: line contains a JSON GenerateContentResponse object:
Set system instructions
UsesystemInstruction to guide the response. This example requests one equation without additional text:
Request JSON output
SetresponseMimeType to application/json and provide a responseSchema. This example requests an array of planets with names and numeric distances:
Ground with Google Search
Add agoogleSearch tool to request search grounding. This example asks for the result of the UEFA EURO 2024 final:
groundingMetadata for search queries, source URLs, and links between sources and response text.
Preserve conversation content
For multi-turn conversations, send the precedinguser and model content in contents. The SDK chat examples maintain this history for you.
For function calling, return one functionResponse for each functionCall, with the matching name and any returned id. Pass the preceding model content back unchanged, including thoughtSignature fields. The signature is opaque; do not reconstruct it from displayed text.
Response example
A text response includes generated content and token usage. This abbreviated example omits optional fields:thoughtsTokenCount reports internal thinking tokens, even when the response does not include a thinking summary. Inspect each content part; a response can contain text, summaries, or function calls.Compare request formats
Choose the native endpoint for Gemini request and response fields. See Chat Completions for the OpenAI-compatible format.Authorizations
Your CometAPI key passed via the x-goog-api-key header. Bearer token authentication (Authorization: Bearer $COMETAPI_KEY) is also supported.
Path Parameters
Gemini model ID. These examples use gemini-3.8-flash. See the Models page for available model IDs.
Operation to perform. Use generateContent for a JSON response. For Server-Sent Events, select streamGenerateContent and set the separate alt query parameter to sse.
generateContent, streamGenerateContent Query Parameters
Set to sse when the operator is streamGenerateContent. Omit this parameter for generateContent.
sse Body
Conversation content. Each entry has an optional role (user or model) and a parts array. For tool results, preserve the complete preceding model content, including any thoughtSignature fields.
System instructions that guide the model's behavior across the entire conversation. Text only.
Tools available to the model during generation. Use googleSearch for search grounding.
Configuration for tool usage, such as function calling mode.
Safety filter settings. Override default thresholds for specific harm categories.
Configuration for model generation behavior including temperature, output length, and response format.
The name of cached content to use as context. Format: cachedContents/{id}. See the Gemini context caching documentation for details.
Response
Successful response. For streaming requests, the response is a stream of SSE events, each containing a GenerateContentResponse JSON object prefixed with data:.
The generated response candidates.
Feedback on the prompt, including safety blocking information.
Token usage statistics for the request.
The model version that generated this response.
The timestamp when this response was created (ISO 8601 format).
Unique identifier for this response.