> ## Documentation Index
> Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate content

> Use the Gemini native API format through CometAPI for text generation, multimodal input, reasoning, function calling, Google Search grounding, JSON mode, and streaming.

CometAPI supports the Gemini native API format, giving you full access to Gemini-specific features like thinking control, Google Search grounding, native image generation modalities, and more. Use this endpoint when you need capabilities not available through the [OpenAI-compatible chat endpoint](/api/text/chat).

<Tip>
  For an OpenAI-compatible Gemini first request, start with the [Gemini API quickstart](/quickstarts/text/gemini-api). Use this reference when you need Gemini native fields.
</Tip>

<Warning>
  Gemini request parameters and response fields can change as Google updates the native API. Check the [Gemini text generation documentation](https://ai.google.dev/gemini-api/docs/text-generation) for the latest complete parameter list and provider-specific behavior.
</Warning>

<Note>
  Both `x-goog-api-key` and `Authorization: Bearer` headers are supported for authentication.
</Note>

## Quick start

To use any Gemini SDK or HTTP client with CometAPI, replace the base URL and API key:

| Setting  | Google Default                      | CometAPI           |
| -------- | ----------------------------------- | ------------------ |
| Base URL | `generativelanguage.googleapis.com` | `api.cometapi.com` |
| API key  | `$GEMINI_API_KEY`                   | `$COMETAPI_KEY`    |

## Send video input

Gemini `generateContent` accepts video as a content part. Choose the input shape based on where the video is stored:

| Video source     | Request part       | Use when                                                                                |
| ---------------- | ------------------ | --------------------------------------------------------------------------------------- |
| Local video file | `inlineData`       | The video is small enough to send as base64 in the JSON request.                        |
| Public video URL | `fileData.fileUri` | The video is available through a public HTTPS URL that does not require authentication. |

<Note>
  For REST and curl requests, use Gemini's camelCase field names such as `inlineData.mimeType` and `fileData.fileUri`. Do not send URL media as `file_data.file_uri`.
</Note>

This example reads a local MP4 file, encodes it as base64, and sends it in the request body:

```sh theme={null}
read -rsp "CometAPI API key: " COMETAPI_KEY
printf '\n'
export COMETAPI_KEY
VIDEO_PATH="./your_video.mp4"
VIDEO_B64=$(base64 < "$VIDEO_PATH" | tr -d '\n')

curl -X POST \
  "https://api.cometapi.com/v1beta/models/gemini-3.5-flash:generateContent" \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: $COMETAPI_KEY" \
  --data-binary @- <<EOF
{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "inlineData": {
            "mimeType": "video/mp4",
            "data": "${VIDEO_B64}"
          }
        },
        {
          "text": "Analyze this video and list the key scenes."
        }
      ]
    }
  ],
  "generationConfig": {
    "maxOutputTokens": 512,
    "thinkingConfig": {"thinkingLevel": "MINIMAL"}
  }
}
EOF
```

This example sends a public MP4 URL with `fileData.fileUri`:

```sh theme={null}
read -rsp "CometAPI API key: " COMETAPI_KEY
printf '\n'
export COMETAPI_KEY
VIDEO_URL="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4"

curl -X POST \
  "https://api.cometapi.com/v1beta/models/gemini-3.5-flash:generateContent" \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: $COMETAPI_KEY" \
  --data-binary @- <<EOF
{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "fileData": {
            "mimeType": "video/mp4",
            "fileUri": "${VIDEO_URL}"
          }
        },
        {
          "text": "Analyze this video and list the key scenes."
        }
      ]
    }
  ],
  "generationConfig": {
    "maxOutputTokens": 512,
    "thinkingConfig": {"thinkingLevel": "MINIMAL"}
  }
}
EOF
```

CometAPI does not recommend a separate Gemini Files API upload flow for this endpoint. Send media in the `generateContent` request itself with `inlineData` or `fileData.fileUri`.

## Configure thinking (reasoning)

Gemini models can perform internal reasoning before generating a response. The control method depends on the model generation.

<Tabs>
  <Tab title="Gemini 3 (thinkingLevel)">
    Gemini 3 models use `thinkingLevel` to control reasoning depth. Available levels: `MINIMAL`, `LOW`, `MEDIUM`, `HIGH`.

    Use `gemini-3-flash-preview` as the default example model unless you specifically need a different Gemini 3 variant.

    ```sh theme={null}
    curl "https://api.cometapi.com/v1beta/models/gemini-3-flash-preview:generateContent" \
      -H "Content-Type: application/json" \
      -H "x-goog-api-key: $COMETAPI_KEY" \
      -d '{
        "contents": [{"parts": [{"text": "Explain quantum physics simply."}]}],
        "generationConfig": {
          "thinkingConfig": {"thinkingLevel": "LOW"}
        }
      }'
    ```
  </Tab>

  <Tab title="Gemini 2.5 (thinkingBudget)">
    Gemini 2.5 models use `thinkingBudget` for fine-grained token-level control:

    * `0` — disable thinking
    * `-1` — dynamic (model decides, default)
    * `> 0` — specific token budget (e.g., `1024`, `2048`)

    ```sh theme={null}
    curl "https://api.cometapi.com/v1beta/models/gemini-2.5-flash:generateContent" \
      -H "Content-Type: application/json" \
      -H "x-goog-api-key: $COMETAPI_KEY" \
      -d '{
        "contents": [{"parts": [{"text": "Solve this logic puzzle step by step."}]}],
        "generationConfig": {
          "thinkingConfig": {"thinkingBudget": 2048}
        }
      }'
    ```
  </Tab>
</Tabs>

<Warning>
  Using `thinkingLevel` with Gemini 2.5 models (or `thinkingBudget` with Gemini 3 models) may cause errors. Use the correct parameter for your model version.
</Warning>

***

## Stream responses

To receive Server-Sent Events as the model generates content, use `streamGenerateContent?alt=sse` as the operator. Each SSE event contains a `data:` line with a JSON `GenerateContentResponse` object.

```sh theme={null}
curl "https://api.cometapi.com/v1beta/models/gemini-3-flash-preview:streamGenerateContent?alt=sse" \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: $COMETAPI_KEY" \
  --no-buffer \
  -d '{
    "contents": [{"parts": [{"text": "Write a short poem about the stars"}]}]
  }'
```

***

## Set system instructions

To guide the model’s behavior across the entire conversation, use `systemInstruction`:

```sh theme={null}
curl "https://api.cometapi.com/v1beta/models/gemini-3-flash-preview:generateContent" \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: $COMETAPI_KEY" \
  -d '{
    "contents": [{"parts": [{"text": "What is 2+2?"}]}],
    "systemInstruction": {
      "parts": [{"text": "You are a math tutor. Always show your work."}]
    }
  }'
```

***

## Request JSON output

To force structured JSON output, set `responseMimeType`. Optionally provide a `responseSchema` for strict schema validation:

```sh theme={null}
curl "https://api.cometapi.com/v1beta/models/gemini-3-flash-preview:generateContent" \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: $COMETAPI_KEY" \
  -d '{
    "contents": [{"parts": [{"text": "List 3 planets with their distances from the sun"}]}],
    "generationConfig": {
      "responseMimeType": "application/json"
    }
  }'
```

***

## Ground with Google Search

To enable real-time web search, add a `googleSearch` tool:

```sh theme={null}
curl "https://api.cometapi.com/v1beta/models/gemini-3-flash-preview:generateContent" \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: $COMETAPI_KEY" \
  -d '{
    "contents": [{"parts": [{"text": "Who won the euro 2024?"}]}],
    "tools": [{"google_search": {}}]
  }'
```

The response includes `groundingMetadata` with source URLs and confidence scores.

***

## Response example

A typical response from CometAPI's Gemini endpoint:

```json theme={null}
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [{"text": "Hello"}]
      },
      "finishReason": "STOP",
      "avgLogprobs": -0.0023
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 5,
    "candidatesTokenCount": 1,
    "totalTokenCount": 30,
    "trafficType": "ON_DEMAND",
    "thoughtsTokenCount": 24,
    "promptTokensDetails": [{"modality": "TEXT", "tokenCount": 5}],
    "candidatesTokensDetails": [{"modality": "TEXT", "tokenCount": 1}]
  },
  "modelVersion": "gemini-3-flash-preview",
  "createTime": "2026-03-25T04:21:43.756483Z",
  "responseId": "CeynaY3LDtvG4_UP0qaCuQY"
}
```

<Info>
  The `thoughtsTokenCount` field in `usageMetadata` shows how many tokens the model spent on internal reasoning, even when thinking output is not included in the response.
</Info>

***

## Compare with OpenAI-compatible endpoint

| Feature                   | Gemini Native (`/v1beta/models/...`)                     | OpenAI-Compatible (`/v1/chat/completions`) |
| ------------------------- | -------------------------------------------------------- | ------------------------------------------ |
| Thinking control          | `thinkingConfig` with `thinkingLevel` / `thinkingBudget` | Not available                              |
| Google Search grounding   | `tools: [\{"google_search": \{\}\}]`                     | Not available                              |
| Google Maps grounding     | `tools: [\{"googleMaps": \{\}\}]`                        | Not available                              |
| Image generation modality | `responseModalities: ["IMAGE"]`                          | Not available                              |
| Auth header               | `x-goog-api-key` or `Bearer`                             | `Bearer` only                              |
| Response format           | Gemini native (`candidates`, `parts`)                    | OpenAI format (`choices`, `message`)       |


## OpenAPI

````yaml api/openapi/text/post-gemini-generating-content.openapi.json POST /v1beta/models/{model}:{operator}
openapi: 3.1.0
info:
  title: Gemini Generating Content API
  version: 1.0.0
servers:
  - url: https://api.cometapi.com
security:
  - apiKeyAuth: []
paths:
  /v1beta/models/{model}:{operator}:
    post:
      summary: Gemini Generating Content
      description: >-
        Generates content using Google Gemini models via the native Gemini API
        format. Supports text generation, multimodal inputs, thinking/reasoning,
        function calling, Google Search grounding, structured output, and
        streaming. CometAPI proxies requests to Google's Gemini API — use this
        endpoint when you need Gemini-native features not available through the
        OpenAI-compatible endpoint.
      operationId: gemini_generating_content
      parameters:
        - name: model
          in: path
          required: true
          description: >-
            Gemini model ID. Example: `gemini-3-flash-preview`,
            `gemini-2.5-pro`. See the [Models page](/overview/models) for
            current options.
          schema:
            type: string
        - name: operator
          in: path
          required: true
          description: >-
            The operation to perform. Use `generateContent` for synchronous
            responses, or `streamGenerateContent?alt=sse` for Server-Sent Events
            streaming.
          schema:
            type: string
            enum:
              - generateContent
              - streamGenerateContent?alt=sse
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: []
              properties:
                contents:
                  type: array
                  items:
                    type: object
                    properties:
                      role:
                        description: >-
                          The role of the content author. Use `user` for user
                          messages and `model` for assistant responses in
                          multi-turn conversations. Can be omitted for
                          single-turn requests.
                        enum:
                          - user
                          - model
                      parts:
                        description: >-
                          The content parts for this turn. Supports text, inline
                          base64 media, public file URLs, and function call
                          results.
                        items:
                          type: object
                          properties:
                            text:
                              type: string
                              description: Text content of this part.
                            inlineData:
                              type: object
                              description: >-
                                Inline binary media sent as base64 in the
                                request. Use this for local image, audio, video,
                                PDF, or other supported media files that are
                                small enough to include in the JSON body. Omit
                                this field when using `fileData`.
                              properties:
                                mimeType:
                                  type: string
                                  description: >-
                                    The MIME type of the media bytes, such as
                                    `image/png`, `audio/mpeg`, `video/mp4`, or
                                    `application/pdf`.
                                data:
                                  type: string
                                  description: >-
                                    Base64-encoded file bytes. Do not include a
                                    `data:video/mp4;base64,` prefix.
                            fileData:
                              type: object
                              description: >-
                                A media file referenced by URL. Use this for
                                public HTTPS video, image, audio, or document
                                URLs that the model provider can fetch without
                                authentication. Omit this field when using
                                `inlineData`.
                              properties:
                                mimeType:
                                  type: string
                                  description: >-
                                    The MIME type of the referenced file, such
                                    as `video/mp4`, `image/png`, `audio/mpeg`,
                                    or `application/pdf`.
                                fileUri:
                                  type: string
                                  description: >-
                                    A public HTTPS URL for the media file. The
                                    URL must not require cookies, private
                                    headers, or a signed-in session.
                            functionCall:
                              type: object
                              description: A function call generated by the model.
                              properties:
                                name:
                                  type: string
                                  description: The function name.
                                args:
                                  type: object
                                  description: The function arguments as a JSON object.
                            functionResponse:
                              type: object
                              description: >-
                                The result of a function call, provided by the
                                user.
                              properties:
                                name:
                                  type: string
                                  description: The function name.
                                response:
                                  type: object
                                  description: The function response as a JSON object.
                  description: >-
                    Conversation content. Each entry has an optional `role`
                    (`user` or `model`) and a `parts` array.
                systemInstruction:
                  type: object
                  description: >-
                    System instructions that guide the model's behavior across
                    the entire conversation. Text only.
                  properties:
                    parts:
                      type: array
                      items:
                        type: object
                        properties:
                          text:
                            type: string
                            description: The system instruction text.
                      description: Content parts of the system instruction.
                tools:
                  type: array
                  description: >-
                    Tools the model may use to generate responses. Supports
                    function declarations, Google Search, Google Maps, and code
                    execution.
                  items:
                    type: object
                    properties:
                      functionDeclarations:
                        type: array
                        description: A list of function declarations for function calling.
                        items:
                          type: object
                          properties:
                            name:
                              type: string
                              description: The function name.
                            description:
                              type: string
                              description: A description of what the function does.
                            parameters:
                              type: object
                              description: The function parameters as a JSON Schema object.
                      googleSearch:
                        type: object
                        description: >-
                          Enable Google Search grounding. Pass an empty object
                          `{}` to enable.
                      googleMaps:
                        type: object
                        description: >-
                          Enable Google Maps grounding. Pass an empty object
                          `{}` to enable.
                      codeExecution:
                        type: object
                        description: >-
                          Enable code execution. Pass an empty object `{}` to
                          enable.
                toolConfig:
                  type: object
                  description: Configuration for tool usage, such as function calling mode.
                  properties:
                    functionCallingConfig:
                      type: object
                      description: Configuration for function calling behavior.
                      properties:
                        mode:
                          type: string
                          description: The function calling mode.
                          enum:
                            - AUTO
                            - ANY
                            - NONE
                        allowedFunctionNames:
                          type: array
                          description: >-
                            Restrict the model to calling only these functions.
                            Only effective when `mode` is `ANY`.
                          items:
                            type: string
                    retrievalConfig:
                      type: object
                      description: >-
                        Configuration for retrieval-based tools (e.g., Google
                        Maps location context).
                      properties:
                        latLng:
                          type: object
                          description: Latitude and longitude for location-based grounding.
                          properties:
                            latitude:
                              type: number
                              description: Latitude in degrees.
                            longitude:
                              type: number
                              description: Longitude in degrees.
                safetySettings:
                  type: array
                  description: >-
                    Safety filter settings. Override default thresholds for
                    specific harm categories.
                  items:
                    type: object
                    properties:
                      category:
                        type: string
                        description: The harm category to configure.
                        enum:
                          - HARM_CATEGORY_HARASSMENT
                          - HARM_CATEGORY_HATE_SPEECH
                          - HARM_CATEGORY_SEXUALLY_EXPLICIT
                          - HARM_CATEGORY_DANGEROUS_CONTENT
                          - HARM_CATEGORY_CIVIC_INTEGRITY
                      threshold:
                        type: string
                        description: The blocking threshold for this category.
                        enum:
                          - BLOCK_NONE
                          - BLOCK_ONLY_HIGH
                          - BLOCK_MEDIUM_AND_ABOVE
                          - BLOCK_LOW_AND_ABOVE
                          - 'OFF'
                generationConfig:
                  type: object
                  description: >-
                    Configuration for model generation behavior including
                    temperature, output length, and response format.
                  properties:
                    temperature:
                      type: number
                      description: >-
                        Controls randomness in output generation. Range:
                        0.0–2.0. For Gemini 3 models, keeping the default (1.0)
                        is strongly recommended — lower values may cause looping
                        or degraded reasoning.
                      minimum: 0
                      maximum: 2
                    topP:
                      type: number
                      description: >-
                        Nucleus sampling threshold. Tokens are considered in
                        order of probability until the cumulative probability
                        reaches this value.
                      minimum: 0
                      maximum: 1
                    topK:
                      type: integer
                      description: >-
                        Maximum number of tokens to consider when sampling. Not
                        supported by all models.
                    maxOutputTokens:
                      type: integer
                      description: >-
                        Maximum number of tokens in the generated response. The
                        default varies by model.
                    candidateCount:
                      type: integer
                      description: >-
                        Number of response candidates to generate. Defaults to
                        1. Not supported by Gemini 1.0 models.
                    stopSequences:
                      type: array
                      description: >-
                        Up to 5 character sequences that will stop output
                        generation. The stop sequence is not included in the
                        response.
                      items:
                        type: string
                      maxItems: 5
                    seed:
                      type: integer
                      description: >-
                        Seed for deterministic generation. If not set, a random
                        seed is used.
                    presencePenalty:
                      type: number
                      description: >-
                        Penalizes tokens that have already appeared in the
                        response (binary on/off per token). Positive values
                        encourage diverse vocabulary.
                    frequencyPenalty:
                      type: number
                      description: >-
                        Penalizes tokens proportionally to how many times they
                        have appeared. Positive values discourage repetition.
                    responseMimeType:
                      type: string
                      description: >-
                        The MIME type for the response. Use `application/json`
                        for JSON mode, `text/x.enum` for enum output, or
                        `text/plain` (default) for free text.
                      enum:
                        - text/plain
                        - application/json
                        - text/x.enum
                    responseSchema:
                      type: object
                      description: >-
                        Output schema for structured responses (JSON Schema
                        subset). Requires `responseMimeType` to be
                        `application/json`.
                    responseModalities:
                      type: array
                      description: >-
                        The expected modalities in the response. Use `["TEXT"]`
                        for text-only, `["IMAGE"]` for images, or `["TEXT",
                        "IMAGE"]` for both. An empty list defaults to text only.
                      items:
                        type: string
                        enum:
                          - TEXT
                          - IMAGE
                          - AUDIO
                    responseLogprobs:
                      type: boolean
                      description: If `true`, include log probabilities in the response.
                    logprobs:
                      type: integer
                      description: >-
                        Number of top log probabilities to return per token
                        (0–20). Only valid when `responseLogprobs` is `true`.
                      minimum: 0
                      maximum: 20
                    thinkingConfig:
                      type: object
                      description: >-
                        Controls the model's internal reasoning (thinking)
                        process. Supported by Gemini 2.5 and later models.
                      properties:
                        thinkingBudget:
                          type: integer
                          description: >-
                            Maximum number of thinking tokens the model may use.
                            Use this for fine-grained control (Gemini 2.5
                            models).
                        thinkingLevel:
                          type: string
                          description: >-
                            Controls the depth of reasoning using a preset
                            level. Recommended for Gemini 3 models. Using this
                            with earlier models may result in an error.
                          enum:
                            - MINIMAL
                            - LOW
                            - MEDIUM
                            - HIGH
                        includeThoughts:
                          type: boolean
                          description: >-
                            If `true`, include the model's thinking process in
                            the response parts.
                    imageConfig:
                      type: object
                      description: >-
                        Configuration for image generation. Only applicable to
                        models that support image output.
                      properties:
                        aspectRatio:
                          type: string
                          description: The aspect ratio for generated images.
                          enum:
                            - '1:1'
                            - '2:3'
                            - '3:2'
                            - '3:4'
                            - '4:3'
                            - '4:5'
                            - '5:4'
                            - '9:16'
                            - '16:9'
                            - '21:9'
                        imageSize:
                          type: string
                          description: The resolution of generated images.
                          enum:
                            - 1K
                            - 2K
                            - 4K
                          default: 1K
                    mediaResolution:
                      type: string
                      description: Resolution for processing input media files.
                      enum:
                        - MEDIA_RESOLUTION_LOW
                        - MEDIA_RESOLUTION_MEDIUM
                        - MEDIA_RESOLUTION_HIGH
                cachedContent:
                  type: string
                  description: >-
                    The name of cached content to use as context. Format:
                    `cachedContents/{id}`. See the Gemini context caching
                    documentation for details.
            examples:
              Basic text:
                summary: Basic text generation
                value:
                  contents:
                    - parts:
                        - text: Explain how AI works in a few words
              Inline video input:
                summary: Analyze a local MP4 as base64
                description: >-
                  Replace `<base64-encoded-mp4>` with the raw base64 string for
                  your local MP4 file.
                value:
                  contents:
                    - role: user
                      parts:
                        - inlineData:
                            mimeType: video/mp4
                            data: <base64-encoded-mp4>
                        - text: Analyze this video and list the key scenes.
                  generationConfig:
                    maxOutputTokens: 512
                    thinkingConfig:
                      thinkingLevel: MINIMAL
              Public video URL input:
                summary: Analyze a public MP4 URL
                value:
                  contents:
                    - role: user
                      parts:
                        - fileData:
                            mimeType: video/mp4
                            fileUri: >-
                              https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4
                        - text: Analyze this video and list the key scenes.
                  generationConfig:
                    maxOutputTokens: 512
                    thinkingConfig:
                      thinkingLevel: MINIMAL
              System instruction:
                summary: With system instruction
                value:
                  contents:
                    - parts:
                        - text: What is 2+2?
                  systemInstruction:
                    parts:
                      - text: You are a math tutor. Be concise.
              Thinking Budget:
                summary: With thinking budget (Gemini 2.5)
                value:
                  contents:
                    - parts:
                        - text: >-
                            Solve this step by step: What is the 10th Fibonacci
                            number?
                  generationConfig:
                    thinkingConfig:
                      thinkingBudget: 2048
              Thinking Level:
                summary: With thinking level (Gemini 3)
                value:
                  contents:
                    - parts:
                        - text: How does quantum computing work?
                  generationConfig:
                    thinkingConfig:
                      thinkingLevel: LOW
              JSON mode:
                summary: Structured JSON output
                value:
                  contents:
                    - parts:
                        - text: List 3 planets with their distances from the sun
                  generationConfig:
                    responseMimeType: application/json
      responses:
        '200':
          description: >-
            Successful response. For streaming requests, the response is a
            stream of SSE events, each containing a `GenerateContentResponse`
            JSON object prefixed with `data: `.
          content:
            application/json:
              schema:
                type: object
                properties:
                  candidates:
                    type: array
                    description: The generated response candidates.
                    items:
                      type: object
                      properties:
                        content:
                          type: object
                          description: The generated content.
                          properties:
                            role:
                              type: string
                              description: Always `model` for generated responses.
                            parts:
                              type: array
                              description: The content parts of the response.
                              items:
                                type: object
                                properties:
                                  text:
                                    type: string
                                    description: Generated text content.
                                  functionCall:
                                    type: object
                                    description: >-
                                      A function call request from the model
                                      (when using function calling tools).
                                    properties:
                                      name:
                                        type: string
                                        description: >-
                                          Name of the function the model wants to
                                          call.
                                      args:
                                        type: object
                                        description: Function arguments as a JSON object.
                                  inlineData:
                                    type: object
                                    description: >-
                                      Inline binary data (e.g., generated
                                      images).
                                    properties:
                                      mimeType:
                                        type: string
                                        description: >-
                                          MIME type of the inline data, such as
                                          `image/png`.
                                      data:
                                        type: string
                                        description: Base64-encoded bytes of the inline data.
                                  thought:
                                    type: boolean
                                    description: >-
                                      `true` if this part contains the model's
                                      thinking/reasoning process (when
                                      `includeThoughts` is enabled).
                        finishReason:
                          type: string
                          description: The reason the model stopped generating tokens.
                          enum:
                            - STOP
                            - MAX_TOKENS
                            - SAFETY
                            - RECITATION
                            - LANGUAGE
                            - OTHER
                            - BLOCKLIST
                            - PROHIBITED_CONTENT
                            - SPII
                            - MALFORMED_FUNCTION_CALL
                        safetyRatings:
                          type: array
                          description: Safety ratings for this candidate.
                          items:
                            type: object
                            properties:
                              category:
                                type: string
                                description: Safety category this rating applies to.
                              probability:
                                type: string
                                description: >-
                                  Probability level for harmful content in this
                                  category, such as `NEGLIGIBLE` or `HIGH`.
                              blocked:
                                type: boolean
                                description: Whether content was blocked for this category.
                        citationMetadata:
                          type: object
                          description: Citation information for model-generated content.
                          properties:
                            citationSources:
                              type: array
                              items:
                                type: object
                                properties:
                                  startIndex:
                                    type: integer
                                    description: >-
                                      Start byte index of the cited span in the
                                      output.
                                  endIndex:
                                    type: integer
                                    description: >-
                                      End byte index of the cited span in the
                                      output.
                                  uri:
                                    type: string
                                    description: URI of the cited source.
                                  license:
                                    type: string
                                    description: License of the cited source when known.
                              description: Sources cited for the generated content.
                        tokenCount:
                          type: integer
                          description: Token count for this candidate.
                        avgLogprobs:
                          type: number
                          description: Average log probability score of this candidate.
                        groundingMetadata:
                          type: object
                          description: >-
                            Grounding metadata when Google Search or other
                            grounding tools are used.
                          properties:
                            groundingChunks:
                              type: array
                              items:
                                type: object
                                properties:
                                  web:
                                    type: object
                                    properties:
                                      uri:
                                        type: string
                                        description: URI of the grounding source.
                                      title:
                                        type: string
                                        description: Title of the grounding source page.
                                    description: A web source used for grounding.
                              description: >-
                                Web sources that ground the response when Google
                                Search grounding runs.
                            groundingSupports:
                              type: array
                              items:
                                type: object
                                properties:
                                  groundingChunkIndices:
                                    type: array
                                    items:
                                      type: integer
                                    description: >-
                                      Indexes into `groundingChunks` that
                                      support this segment.
                                  confidenceScores:
                                    type: array
                                    items:
                                      type: number
                                    description: >-
                                      Support confidence per grounding chunk,
                                      between 0 and 1.
                                  segment:
                                    type: object
                                    properties:
                                      startIndex:
                                        type: integer
                                        description: Start byte index of the segment.
                                      endIndex:
                                        type: integer
                                        description: End byte index of the segment.
                                      text:
                                        type: string
                                        description: Text of the segment.
                                    description: >-
                                      The output text segment this support entry
                                      covers.
                              description: >-
                                Mapping between output text segments and the
                                grounding chunks that support them.
                            webSearchQueries:
                              type: array
                              items:
                                type: string
                              description: Search queries the model issued for grounding.
                        index:
                          type: integer
                          description: >-
                            Index of this candidate in the list of response
                            candidates.
                  promptFeedback:
                    type: object
                    description: >-
                      Feedback on the prompt, including safety blocking
                      information.
                    properties:
                      blockReason:
                        type: string
                        description: If set, the prompt was blocked.
                        enum:
                          - SAFETY
                          - OTHER
                          - BLOCKLIST
                          - PROHIBITED_CONTENT
                      safetyRatings:
                        type: array
                        items:
                          type: object
                          properties:
                            category:
                              type: string
                              description: Safety category this rating applies to.
                            probability:
                              type: string
                              description: >-
                                Probability level for harmful content in this
                                category.
                            blocked:
                              type: boolean
                              description: >-
                                Whether the prompt was blocked for this
                                category.
                        description: Safety ratings for the prompt.
                  usageMetadata:
                    type: object
                    description: Token usage statistics for the request.
                    properties:
                      promptTokenCount:
                        type: integer
                        description: Number of tokens in the prompt.
                      candidatesTokenCount:
                        type: integer
                        description: Number of tokens across all generated candidates.
                      totalTokenCount:
                        type: integer
                        description: Total token count (prompt + candidates + thinking).
                      trafficType:
                        type: string
                        description: >-
                          The traffic type used for processing (e.g.,
                          `ON_DEMAND`).
                      thoughtsTokenCount:
                        type: integer
                        description: >-
                          Number of tokens used for the model's internal
                          thinking process.
                      promptTokensDetails:
                        type: array
                        description: Token count breakdown by input modality.
                        items:
                          type: object
                          properties:
                            modality:
                              type: string
                              description: >-
                                Input modality this entry counts, such as `TEXT`
                                or `VIDEO`.
                            tokenCount:
                              type: integer
                              description: Prompt tokens for this modality.
                      candidatesTokensDetails:
                        type: array
                        description: Token count breakdown by output modality.
                        items:
                          type: object
                          properties:
                            modality:
                              type: string
                              description: Output modality this entry counts.
                            tokenCount:
                              type: integer
                              description: Output tokens for this modality.
                  modelVersion:
                    type: string
                    description: The model version that generated this response.
                  createTime:
                    type: string
                    description: >-
                      The timestamp when this response was created (ISO 8601
                      format).
                  responseId:
                    type: string
                    description: Unique identifier for this response.
      x-codeSamples:
        - lang: Python
          label: Basic
          source: |
            import os
            from google import genai

            client = genai.Client(
                api_key=os.environ["COMETAPI_KEY"],
                http_options={"api_version": "v1beta", "base_url": "https://api.cometapi.com"},
            )

            response = client.models.generate_content(
                model="gemini-3-flash-preview",
                contents="Explain how AI works in a few words",
            )

            print(response.text)
        - lang: Python
          label: System Instruction
          source: |
            import os
            from google import genai
            from google.genai import types

            client = genai.Client(
                api_key=os.environ["COMETAPI_KEY"],
                http_options={"api_version": "v1beta", "base_url": "https://api.cometapi.com"},
            )

            response = client.models.generate_content(
                model="gemini-3-flash-preview",
                contents="What is 2+2?",
                config=types.GenerateContentConfig(
                    system_instruction="You are a math tutor. Be concise.",
                    temperature=0.5,
                ),
            )

            print(response.text)
        - lang: Python
          label: Thinking Budget
          source: |
            import os
            from google import genai
            from google.genai import types

            client = genai.Client(
                api_key=os.environ["COMETAPI_KEY"],
                http_options={"api_version": "v1beta", "base_url": "https://api.cometapi.com"},
            )

            response = client.models.generate_content(
                model="gemini-2.5-flash",
                contents="Solve this step by step: What is the 10th Fibonacci number?",
                config=types.GenerateContentConfig(
                    thinking_config=types.ThinkingConfig(thinking_budget=2048),
                ),
            )

            print(response.text)
        - lang: Python
          label: Google Search
          source: |
            import os
            from google import genai
            from google.genai import types

            client = genai.Client(
                api_key=os.environ["COMETAPI_KEY"],
                http_options={"api_version": "v1beta", "base_url": "https://api.cometapi.com"},
            )

            response = client.models.generate_content(
                model="gemini-3-flash-preview",
                contents="Who won the euro 2024?",
                config=types.GenerateContentConfig(
                    tools=[types.Tool(google_search=types.GoogleSearch())],
                ),
            )

            print(response.text)
        - lang: Python
          label: JSON Mode
          source: |
            import os
            from google import genai
            from google.genai import types

            client = genai.Client(
                api_key=os.environ["COMETAPI_KEY"],
                http_options={"api_version": "v1beta", "base_url": "https://api.cometapi.com"},
            )

            response = client.models.generate_content(
                model="gemini-3-flash-preview",
                contents="List 3 planets with their distances from the sun",
                config=types.GenerateContentConfig(
                    response_mime_type="application/json",
                ),
            )

            print(response.text)
        - lang: Python
          label: Streaming
          source: |
            import os
            from google import genai

            client = genai.Client(
                api_key=os.environ["COMETAPI_KEY"],
                http_options={"api_version": "v1beta", "base_url": "https://api.cometapi.com"},
            )

            response = client.models.generate_content_stream(
                model="gemini-3-flash-preview",
                contents="Write a short poem about the stars",
            )

            for chunk in response:
                print(chunk.text, end="")
        - lang: Python
          label: Multi-turn Chat
          source: |
            import os
            from google import genai

            client = genai.Client(
                api_key=os.environ["COMETAPI_KEY"],
                http_options={"api_version": "v1beta", "base_url": "https://api.cometapi.com"},
            )

            chat = client.chats.create(model="gemini-3-flash-preview")

            response = chat.send_message("I have 2 dogs.")
            print(response.text)

            response = chat.send_message("How many paws are in my house?")
            print(response.text)
        - lang: Python
          label: Thinking Level
          source: |
            import os
            from google import genai
            from google.genai import types

            client = genai.Client(
                api_key=os.environ["COMETAPI_KEY"],
                http_options={"api_version": "v1beta", "base_url": "https://api.cometapi.com"},
            )

            response = client.models.generate_content(
                model="gemini-3-flash-preview",
                contents="How does quantum computing work?",
                config=types.GenerateContentConfig(
                    thinking_config=types.ThinkingConfig(thinking_level="LOW"),
                ),
            )

            print(response.text)
        - lang: Python
          label: Inline Video
          source: |
            import os
            from google import genai
            from google.genai import types

            client = genai.Client(
                api_key=os.environ["COMETAPI_KEY"],
                http_options={"api_version": "v1beta", "base_url": "https://api.cometapi.com"},
            )

            with open("your_video.mp4", "rb") as f:
                video_bytes = f.read()

            response = client.models.generate_content(
                model="gemini-3.5-flash",
                contents=[
                    types.Part.from_bytes(data=video_bytes, mime_type="video/mp4"),
                    "Summarize this video.",
                ],
            )

            print(response.text)
        - lang: Python
          label: Public Video URL
          source: |
            import os
            from google import genai
            from google.genai import types

            client = genai.Client(
                api_key=os.environ["COMETAPI_KEY"],
                http_options={"api_version": "v1beta", "base_url": "https://api.cometapi.com"},
            )

            response = client.models.generate_content(
                model="gemini-3.5-flash",
                contents=[
                    types.Part.from_uri(
                        file_uri="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4",
                        mime_type="video/mp4",
                    ),
                    "Analyze this video and list the key scenes.",
                ],
            )

            print(response.text)
        - lang: JavaScript
          label: Basic
          source: |
            import { GoogleGenAI } from "@google/genai";

            const ai = new GoogleGenAI({
                apiKey: process.env.COMETAPI_KEY,
                httpOptions: { apiVersion: "v1beta", baseUrl: "https://api.cometapi.com" },
            });

            const response = await ai.models.generateContent({
                model: "gemini-3-flash-preview",
                contents: "Explain how AI works in a few words",
            });

            console.log(response.text);
        - lang: JavaScript
          label: System Instruction
          source: |
            import { GoogleGenAI } from "@google/genai";

            const ai = new GoogleGenAI({
                apiKey: process.env.COMETAPI_KEY,
                httpOptions: { apiVersion: "v1beta", baseUrl: "https://api.cometapi.com" },
            });

            const response = await ai.models.generateContent({
                model: "gemini-3-flash-preview",
                contents: "What is 2+2?",
                config: {
                    systemInstruction: "You are a math tutor. Be concise.",
                    temperature: 0.5,
                },
            });

            console.log(response.text);
        - lang: JavaScript
          label: Thinking Budget
          source: |
            import { GoogleGenAI } from "@google/genai";

            const ai = new GoogleGenAI({
                apiKey: process.env.COMETAPI_KEY,
                httpOptions: { apiVersion: "v1beta", baseUrl: "https://api.cometapi.com" },
            });

            const response = await ai.models.generateContent({
                model: "gemini-2.5-flash",
                contents: "Solve this step by step: What is the 10th Fibonacci number?",
                config: {
                    thinkingConfig: { thinkingBudget: 2048 },
                },
            });

            console.log(response.text);
        - lang: JavaScript
          label: Thinking Level
          source: |
            import { GoogleGenAI } from "@google/genai";

            const ai = new GoogleGenAI({
                apiKey: process.env.COMETAPI_KEY,
                httpOptions: { apiVersion: "v1beta", baseUrl: "https://api.cometapi.com" },
            });

            const response = await ai.models.generateContent({
                model: "gemini-3-flash-preview",
                contents: "How does quantum computing work?",
                config: {
                    thinkingConfig: { thinkingLevel: "LOW" },
                },
            });

            console.log(response.text);
        - lang: JavaScript
          label: Google Search
          source: |
            import { GoogleGenAI } from "@google/genai";

            const ai = new GoogleGenAI({
                apiKey: process.env.COMETAPI_KEY,
                httpOptions: { apiVersion: "v1beta", baseUrl: "https://api.cometapi.com" },
            });

            const response = await ai.models.generateContent({
                model: "gemini-3-flash-preview",
                contents: "Who won the euro 2024?",
                config: {
                    tools: [{ googleSearch: {} }],
                },
            });

            console.log(response.text);
        - lang: JavaScript
          label: Streaming
          source: |
            import { GoogleGenAI } from "@google/genai";

            const ai = new GoogleGenAI({
                apiKey: process.env.COMETAPI_KEY,
                httpOptions: { apiVersion: "v1beta", baseUrl: "https://api.cometapi.com" },
            });

            const response = await ai.models.generateContentStream({
                model: "gemini-3-flash-preview",
                contents: "Write a short poem about the stars",
            });

            for await (const chunk of response) {
                process.stdout.write(chunk.text);
            }
        - lang: JavaScript
          label: JSON Mode
          source: |
            import { GoogleGenAI } from "@google/genai";

            const ai = new GoogleGenAI({
                apiKey: process.env.COMETAPI_KEY,
                httpOptions: { apiVersion: "v1beta", baseUrl: "https://api.cometapi.com" },
            });

            const response = await ai.models.generateContent({
                model: "gemini-3-flash-preview",
                contents: "List 3 planets with their distances from the sun",
                config: {
                    responseMimeType: "application/json",
                },
            });

            console.log(response.text);
        - lang: JavaScript
          label: Multi-turn Chat
          source: >
            import { GoogleGenAI } from "@google/genai";


            const ai = new GoogleGenAI({
                apiKey: process.env.COMETAPI_KEY,
                httpOptions: { apiVersion: "v1beta", baseUrl: "https://api.cometapi.com" },
            });


            const chat = ai.chats.create({ model: "gemini-3-flash-preview" });


            let response = await chat.sendMessage({ message: "I have 2 dogs."
            });

            console.log(response.text);


            response = await chat.sendMessage({ message: "How many paws are in
            my house?" });

            console.log(response.text);
        - lang: JavaScript
          label: Inline Video
          source: >
            import fs from "node:fs";

            import { GoogleGenAI } from "@google/genai";


            const ai = new GoogleGenAI({
                apiKey: process.env.COMETAPI_KEY,
                httpOptions: { apiVersion: "v1beta", baseUrl: "https://api.cometapi.com" },
            });


            const videoBase64 = fs.readFileSync("your_video.mp4", { encoding:
            "base64" });


            const response = await ai.models.generateContent({
                model: "gemini-3.5-flash",
                contents: [
                    { inlineData: { mimeType: "video/mp4", data: videoBase64 } },
                    { text: "Summarize this video." },
                ],
            });


            console.log(response.text);
        - lang: JavaScript
          label: Public Video URL
          source: |
            import { GoogleGenAI } from "@google/genai";

            const ai = new GoogleGenAI({
                apiKey: process.env.COMETAPI_KEY,
                httpOptions: { apiVersion: "v1beta", baseUrl: "https://api.cometapi.com" },
            });

            const response = await ai.models.generateContent({
                model: "gemini-3.5-flash",
                contents: [
                    {
                        fileData: {
                            mimeType: "video/mp4",
                            fileUri: "https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4",
                        },
                    },
                    { text: "Analyze this video and list the key scenes." },
                ],
            });

            console.log(response.text);
        - lang: Shell
          label: Basic
          source: >
            curl
            "https://api.cometapi.com/v1beta/models/gemini-3-flash-preview:generateContent"
            \
              -H "Content-Type: application/json" \
              -H "x-goog-api-key: $COMETAPI_KEY" \
              -d '{
                "contents": [
                  {
                    "parts": [
                      {"text": "Explain how AI works in a few words"}
                    ]
                  }
                ]
              }'
        - lang: Shell
          label: Inline Video
          source: |
            export COMETAPI_KEY="$COMETAPI_KEY"
            VIDEO_PATH="./your_video.mp4"
            VIDEO_B64=$(base64 < "$VIDEO_PATH" | tr -d '\n')

            curl -X POST \
              "https://api.cometapi.com/v1beta/models/gemini-3.5-flash:generateContent" \
              -H "Content-Type: application/json" \
              -H "x-goog-api-key: $COMETAPI_KEY" \
              --data-binary @- <<EOF
            {
              "contents": [
                {
                  "role": "user",
                  "parts": [
                    {
                      "inlineData": {
                        "mimeType": "video/mp4",
                        "data": "${VIDEO_B64}"
                      }
                    },
                    {
                      "text": "Analyze this video and list the key scenes."
                    }
                  ]
                }
              ],
              "generationConfig": {
                "maxOutputTokens": 512,
                "thinkingConfig": {"thinkingLevel": "MINIMAL"}
              }
            }
            EOF
        - lang: Shell
          label: Public Video URL
          source: >
            export COMETAPI_KEY="$COMETAPI_KEY"

            VIDEO_URL="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4"


            curl -X POST \
              "https://api.cometapi.com/v1beta/models/gemini-3.5-flash:generateContent" \
              -H "Content-Type: application/json" \
              -H "x-goog-api-key: $COMETAPI_KEY" \
              --data-binary @- <<EOF
            {
              "contents": [
                {
                  "role": "user",
                  "parts": [
                    {
                      "fileData": {
                        "mimeType": "video/mp4",
                        "fileUri": "${VIDEO_URL}"
                      }
                    },
                    {
                      "text": "Analyze this video and list the key scenes."
                    }
                  ]
                }
              ],
              "generationConfig": {
                "maxOutputTokens": 512,
                "thinkingConfig": {"thinkingLevel": "MINIMAL"}
              }
            }

            EOF
        - lang: Shell
          label: System Instruction
          source: >
            curl
            "https://api.cometapi.com/v1beta/models/gemini-3-flash-preview:generateContent"
            \
              -H "Content-Type: application/json" \
              -H "x-goog-api-key: $COMETAPI_KEY" \
              -d '{
                "contents": [
                  {"parts": [{"text": "What is 2+2?"}]}
                ],
                "systemInstruction": {
                  "parts": [{"text": "You are a math tutor. Be concise."}]
                },
                "generationConfig": {
                  "temperature": 0.5
                }
              }'
        - lang: Shell
          label: Thinking Budget
          source: >
            curl
            "https://api.cometapi.com/v1beta/models/gemini-2.5-flash:generateContent"
            \
              -H "Content-Type: application/json" \
              -H "x-goog-api-key: $COMETAPI_KEY" \
              -d '{
                "contents": [
                  {"parts": [{"text": "Solve this step by step: What is the 10th Fibonacci number?"}]}
                ],
                "generationConfig": {
                  "thinkingConfig": {"thinkingBudget": 2048}
                }
              }'
        - lang: Shell
          label: Thinking Level
          source: >
            curl
            "https://api.cometapi.com/v1beta/models/gemini-3-flash-preview:generateContent"
            \
              -H "Content-Type: application/json" \
              -H "x-goog-api-key: $COMETAPI_KEY" \
              -d '{
                "contents": [
                  {"parts": [{"text": "How does quantum computing work?"}]}
                ],
                "generationConfig": {
                  "thinkingConfig": {"thinkingLevel": "LOW"}
                }
              }'
        - lang: Shell
          label: JSON Mode
          source: >
            curl
            "https://api.cometapi.com/v1beta/models/gemini-3-flash-preview:generateContent"
            \
              -H "Content-Type: application/json" \
              -H "x-goog-api-key: $COMETAPI_KEY" \
              -d '{
                "contents": [
                  {"parts": [{"text": "List 3 planets with their distances from the sun"}]}
                ],
                "generationConfig": {
                  "responseMimeType": "application/json"
                }
              }'
        - lang: Shell
          label: Streaming
          source: >
            curl
            "https://api.cometapi.com/v1beta/models/gemini-3-flash-preview:streamGenerateContent?alt=sse"
            \
              -H "Content-Type: application/json" \
              -H "x-goog-api-key: $COMETAPI_KEY" \
              -d '{
                "contents": [
                  {"parts": [{"text": "Write a short poem about the stars"}]}
                ]
              }'
        - lang: Shell
          label: Google Search
          source: >
            curl
            "https://api.cometapi.com/v1beta/models/gemini-3-flash-preview:generateContent"
            \
              -H "Content-Type: application/json" \
              -H "x-goog-api-key: $COMETAPI_KEY" \
              -d '{
                "contents": [
                  {"parts": [{"text": "Who won the euro 2024?"}]}
                ],
                "tools": [{"google_search": {}}]
              }'
        - lang: Shell
          label: Multi-turn Chat
          source: >
            curl
            "https://api.cometapi.com/v1beta/models/gemini-3-flash-preview:generateContent"
            \
              -H "Content-Type: application/json" \
              -H "x-goog-api-key: $COMETAPI_KEY" \
              -d '{
                "contents": [
                  {"role": "user", "parts": [{"text": "I have 2 dogs."}]},
                  {"role": "model", "parts": [{"text": "That is wonderful! Dogs are great companions."}]},
                  {"role": "user", "parts": [{"text": "How many paws are in my house?"}]}
                ]
              }'
components:
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: x-goog-api-key
      description: >-
        Your CometAPI key passed via the `x-goog-api-key` header. Bearer token
        authentication (`Authorization: Bearer $COMETAPI_KEY`) is also
        supported.

````