Skip to main content
POST
Use the Gemini native request format through CometAPI to generate text, send video input, and configure thinking or tools. The examples use gemini-3.8-flash.
Use Google’s GenerateContent API reference for field definitions and model-specific options. This page shows the CometAPI base URL, authentication, and request examples.
Both 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: Use the GenerateContent text generation guide for native API examples. Keep the 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:
For REST and curl requests, use camelCase field names such as inlineData.mimeType and fileData.fileUri.
This example sends inline MP4 data. Replace <base64-encoded-mp4> with the base64 contents of your video:
This example analyzes a public MP4 of a flower opening:

Configure thinking (reasoning)

Use thinkingConfig.thinkingLevel to guide reasoning depth. The examples below use LOW and MEDIUM.
This example sets the thinking level to 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

Use streamGenerateContent?alt=sse to receive Server-Sent Events. Each data: line contains a JSON GenerateContentResponse object:

Set system instructions

Use systemInstruction to guide the response. This example requests one equation without additional text:

Request JSON output

Set responseMimeType to application/json and provide a responseSchema. This example requests an array of planets with names and numeric distances:
Add a googleSearch tool to request search grounding. This example asks for the result of the UEFA EURO 2024 final:
When search is used, inspect the candidate’s groundingMetadata for search queries, source URLs, and links between sources and response text.

Preserve conversation content

For multi-turn conversations, send the preceding user 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

x-goog-api-key
string
header
required

Your CometAPI key passed via the x-goog-api-key header. Bearer token authentication (Authorization: Bearer $COMETAPI_KEY) is also supported.

Path Parameters

model
string
default:gemini-3.8-flash
required

Gemini model ID. These examples use gemini-3.8-flash. See the Models page for available model IDs.

operator
enum<string>
default:generateContent
required

Operation to perform. Use generateContent for a JSON response. For Server-Sent Events, select streamGenerateContent and set the separate alt query parameter to sse.

Available options:
generateContent,
streamGenerateContent

Query Parameters

alt
enum<string>

Set to sse when the operator is streamGenerateContent. Omit this parameter for generateContent.

Available options:
sse

Body

application/json
contents
object[]

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.

systemInstruction
object

System instructions that guide the model's behavior across the entire conversation. Text only.

tools
object[]

Tools available to the model during generation. Use googleSearch for search grounding.

toolConfig
object

Configuration for tool usage, such as function calling mode.

safetySettings
object[]

Safety filter settings. Override default thresholds for specific harm categories.

generationConfig
object

Configuration for model generation behavior including temperature, output length, and response format.

cachedContent
string

The name of cached content to use as context. Format: cachedContents/{id}. See the Gemini context caching documentation for details.

Response

200 - application/json

Successful response. For streaming requests, the response is a stream of SSE events, each containing a GenerateContentResponse JSON object prefixed with data:.

candidates
object[]

The generated response candidates.

promptFeedback
object

Feedback on the prompt, including safety blocking information.

usageMetadata
object

Token usage statistics for the request.

modelVersion
string

The model version that generated this response.

createTime
string

The timestamp when this response was created (ISO 8601 format).

responseId
string

Unique identifier for this response.

Last modified on September 7, 2026