TokenLab

Gemini Native

Generate Content

Generates content using Google Gemini API format

POST
/v1beta/models/{model}:generateContent

Use Gemini request and response formats with a model returned by the Gemini Models API. ProtoJSON lowerCamelCase and the corresponding proto snake_case field names are accepted. Supported optional fields and values depend on the selected model.

Path Parameters

modelstringpathrequired

Model name (e.g., gemini-2.5-pro, gemini-3.5-flash).

Query Parameters

keystringquery

API key (alternative to header authentication).

Authentication

Gemini endpoints support multiple authentication methods:

  • ?key=YOUR_API_KEY query parameter
  • x-goog-api-key: YOUR_API_KEY header
  • Authorization: Bearer YOUR_API_KEY header

Request Body

contentsarrayrequired

Conversation contents with parts and an optional role. Media parts use inlineData / inline_data or fileData / file_data. Files and Cache IDs created by TokenLab can only be used in their owning Workspace.

systemInstructionobject

System instruction for the model.

generationConfigobject

Generation settings such as temperature, topP, topK, maxOutputTokens, stopSequences, candidateCount, responseModalities, responseMimeType, responseSchema, and thinkingConfig. Corresponding snake_case names are also accepted. Supported values and combinations depend on the model.

safetySettingsarray

Safety filter settings.

Every lowerCamelCase field shown above may also use its official proto snake_case spelling, for example system_instruction, generation_config, safety_settings, tool_config, cached_content, file_data.file_uri, and inline_data.mime_type.

Supported Methods

The Gemini-compatible API includes model list/get, generateContent, streamGenerateContent, countTokens, embedContent, and batchEmbedContents. Gemini Interactions and Live are not available.

Response

candidatesarray

Generated content candidates.

usageMetadataobject

Token usage information.

Request

curl -X POST "https://api.tokenlab.sh/v1beta/models/gemini-2.5-pro:generateContent?key=sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "parts": [{"text": "Hello, Gemini!"}]
      }
    ],
    "generationConfig": {
      "temperature": 0.7,
      "maxOutputTokens": 1024
    }
  }'

Vision Input Example

For Gemini multimodal requests, place media inside contents[].parts[] using either inline bytes or URL-based file references.

Supported media categories in the public Gemini contract:

  • image
  • audio
  • video

For inline media, use either inlineData or inline_data and pass Base64-encoded file bytes.

For URL-based media, use either fileData or file_data and pass a public https URL.

Video Input Example

{
  "contents": [
    {
      "role": "user",
      "parts": [
        { "text": "Please describe this video." },
        {
          "fileData": {
            "mimeType": "video/mp4",
            "fileUri": "https://example.com/demo.mp4"
          }
        }
      ]
    }
  ]
}

Audio Input Example

{
  "contents": [
    {
      "role": "user",
      "parts": [
        { "text": "Please describe this audio." },
        {
          "fileData": {
            "mimeType": "audio/mpeg",
            "fileUri": "https://example.com/demo.mp3"
          }
        }
      ]
    }
  ]
}

Image Input Example

Use inline image bytes:

{
  "contents": [
    {
      "role": "user",
      "parts": [
        { "text": "Please describe this image." },
        {
          "inlineData": {
            "mimeType": "image/jpeg",
            "data": "/9j/4AAQSkZJRgABAQ..."
          }
        }
      ]
    }
  ]
}

Use an image URL:

{
  "contents": [
    {
      "role": "user",
      "parts": [
        { "text": "Please describe this image." },
        {
          "fileData": {
            "mimeType": "image/jpeg",
            "fileUri": "https://example.com/demo.jpg"
          }
        }
      ]
    }
  ]
}

Audio Input Example

Use an audio URL:

{
  "contents": [
    {
      "role": "user",
      "parts": [
        { "text": "Transcribe and summarize this audio." },
        {
          "file_data": {
            "mime_type": "audio/mpeg",
            "file_uri": "https://example.com/sample.mp3"
          }
        }
      ]
    }
  ]
}

Video Input Example

Use a video URL:

{
  "contents": [
    {
      "role": "user",
      "parts": [
        { "text": "Describe this video briefly." },
        {
          "fileData": {
            "mimeType": "video/mp4",
            "fileUri": "https://example.com/sample.mp4"
          }
        }
      ]
    }
  ]
}

Response

Response
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {"text": "Hello! How can I assist you today?"}
        ]
      },
      "finishReason": "STOP",
      "safetyRatings": [
        {"category": "HARM_CATEGORY_HARASSMENT", "probability": "NEGLIGIBLE"}
      ]
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 5,
    "candidatesTokenCount": 10,
    "totalTokenCount": 15
  }
}

Authorization

BearerAuth
AuthorizationBearer <token>

API Key authentication. Create or manage API keys in Dashboard > API > API Keys.

In: header

Path Parameters

model*string

Model name (e.g., gemini-2.5-pro)

Query Parameters

key?string

API key (alternative to header auth)

Headers

X-TokenLab-Delivery-Policy?string

Per-request Delivery policy. Overrides the API key and Workspace defaults. Auto tries TokenLab Verified first and may switch once to Official only before output, request acceptance, or persistent resource creation.

Value in

  • "auto"
  • "verified"
  • "official"

Request Body

application/json

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.

Response

application/json

application/json

application/json

application/json

application/json

application/json