---
title: "Generate content (Gemini-compatible)"
method: POST
path: "/v1beta/models/{model}:generateContent"
tags: ["Gemini"]
---

# Generate content (Gemini-compatible)

`POST /v1beta/models/{model}:generateContent`

## Request

- Base URL: `https://api.tokenlab.sh`
- URL: `https://api.tokenlab.sh/v1beta/models/{model}:generateContent`
- Auth: HTTP bearer

Generates content using the Gemini GenerateContent request shape. The model details must advertise Gemini requests and the model must be available. ProtoJSON lowerCamelCase and original proto snake_case field names are preserved. Unknown fields are accepted on a best-effort basis; model-specific support is not guaranteed.

**Authentication:** Use `?key=` query parameter, `x-goog-api-key` header, or `Authorization: Bearer` header.

## Path parameters

- `model` string, required

## Query parameters

- `key` string

## Headers

- `X-TokenLab-Delivery-Policy` 'auto' | 'verified' | 'official'

## Request body

- GeminiRequest: Native Gemini GenerateContent request. ProtoJSON lowerCamelCase and original proto snake_case names are both accepted and preserved, including mixed requests. If both spellings of one field are present, TokenLab does not merge them or choose a local precedence. Unknown fields are forwarded on a best-effort basis.
  - `contents` object[], required: Conversation contents
    - `role` 'user' | 'model'
    - `parts` union[]
      - union
        - object
          - `text` string
        - object
          - `inlineData` object
            - `mimeType` string
            - `data` string
        - object
          - `inline_data` object
            - `mime_type` string
            - `data` string
        - object
          - `fileData` object
            - `mimeType` string
            - `fileUri` string
        - object
          - `file_data` object
            - `mime_type` string
            - `file_uri` string
        - object
          - `videoMetadata` object
        - object
          - `video_metadata` object
        - object
          - `thought` boolean
          - `thoughtSignature` string
          - `thought_signature` string
        - object
          - `functionCall` object
        - object
          - `functionResponse` object
        - object
          - `executableCode` object
        - object
          - `codeExecutionResult` object
        - object
          - `function_call` object
        - object
          - `function_response` object
        - object
          - `executable_code` object
        - object
          - `code_execution_result` object
  - `systemInstruction` object
    - `parts` object[]
      - `text` string
  - `generationConfig` object
    - `temperature` number
    - `topP` number
    - `topK` integer
    - `maxOutputTokens` integer
    - `stopSequences` string[]
    - `candidateCount` integer: Requested number of response candidates. Support is determined by the selected service.
    - `responseModalities` string[]: Requested output modalities for supported Gemini models.
    - `responseMimeType` string: Requested output MIME type, such as text/plain or application/json.
    - `responseSchema` object: JSON schema for structured output when responseMimeType requests JSON.
    - `thinkingConfig` object: Thinking budget options for compatible Gemini models.
      - `thinkingBudget` integer
    - `thinking_config` object: Snake-case thinking budget options for compatible Gemini models.
      - `thinking_budget` integer
  - `safetySettings` object[]
    - `category` string
    - `threshold` string
  - `tools` object[]: Gemini tools. Tool types and combinations are interpreted by the selected service.
    - `functionDeclarations` object[]
    - `function_declarations` object[]
    - `codeExecution` object
    - `code_execution` object
    - `googleSearch` object
    - `google_search` object
    - `googleSearchRetrieval` object
    - `google_search_retrieval` object
    - `urlContext` object
    - `url_context` object
    - `computerUse` object
    - `computer_use` object
  - `toolConfig` object: Gemini tool configuration such as functionCallingConfig.
    - `functionCallingConfig` object
      - `mode` string
      - `allowedFunctionNames` string[]
    - `function_calling_config` object
      - `mode` string
      - `allowed_function_names` string[]
  - `cachedContent` string: Gemini cached content resource name for compatible models.
  - `system_instruction` object: Original proto field-name spelling of systemInstruction.
  - `generation_config` object: Original proto field-name spelling of generationConfig.
  - `safety_settings` object[]: Original proto field-name spelling of safetySettings.
  - `tool_config` object: Original proto field-name spelling of toolConfig.
  - `cached_content` string: Original proto field-name spelling of cachedContent.

## Response `200`

Successful response

- GeminiResponse
  - `candidates` object[]
    - `content` object
      - `role` string
      - `parts` object[]
        - `text` string
    - `finishReason` string
    - `safetyRatings` object[]
      - `category` string
      - `probability` string
  - `usageMetadata` object
    - `promptTokenCount` integer
    - `candidatesTokenCount` integer
    - `totalTokenCount` integer

## Other responses

- `400`: Gemini-native invalid request error
- `401`: Gemini-native authentication error
- `402`: Gemini-native payment error
- `500`: Gemini-native server error
- `503`: The requested Delivery tier is temporarily unavailable.

---

[API](https://skmtc.dev/tokenlab/apis/tokenlab-ai-gateway.md) · [All operations](https://skmtc.dev/tokenlab/apis/tokenlab-ai-gateway/llms.txt) · [OpenAPI document](https://skmtc.dev/tokenlab/apis/tokenlab-ai-gateway/revisions/3208bfbcda22?raw)
