---
agent:
  instructions: "Search the site by keyword or question. The search API returns Markdown."
  endpoint: "https://platform.invideo.io/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Gemini

> Use the Google GenAI SDK with Platform: generateContent and streamGenerateContent, passthrough for Gemini models, translated for every other chat model.

# Gemini

`POST /v1beta/models/{model}:generateContent` and
`POST /v1beta/models/{model}:streamGenerateContent?alt=sse` take Gemini's
format, so the Google GenAI SDKs work as they are. Set the base URL to
`https://platform-api.invideo.io` and use your Platform API key.

- **Gemini models: passthrough.** Your body (`contents`, `systemInstruction`,
  `generationConfig`, `tools`, `inlineData` parts, thinking) goes to Gemini as
  is, and the answer comes back as Gemini sends it.
- **Other models: translated.** Text, images, function tools and the system
  instruction carry over.

`{model}` is our id or the provider's own id (its `aliases` in `GET /v1/models`). See [Formats and model IDs](/docs/chat/formats) for
aliases and what every door refuses.

## Send a request

```python
from google import genai
from google.genai import types
import os

client = genai.Client(
    api_key=os.environ["INVIDEO_API_KEY"],
    http_options={"base_url": "https://platform-api.invideo.io", "api_version": "v1beta"},
)

answer = client.models.generate_content(
    model="gemini-4-carbon",
    contents="Name a video app for cooks.",
    config=types.GenerateContentConfig(system_instruction="You write short product names.", max_output_tokens=200),
)
print(answer.text)
print(answer.usage_metadata)  # prompt, answer, cached and thought tokens, and cost_usd
```

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

const client = new GoogleGenAI({ apiKey: process.env.INVIDEO_API_KEY, httpOptions: { baseUrl: "https://platform-api.invideo.io", apiVersion: "v1beta" } });

const answer = await client.models.generateContent({ model: "gemini-4-carbon", contents: "Name a video app for cooks." });
console.log(answer.text);
```

```bash
curl "https://platform-api.invideo.io/v1beta/models/gemini-4-carbon:generateContent" \
  -H "x-goog-api-key: $INVIDEO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"contents": [{"role": "user", "parts": [{"text": "Name a video app for cooks."}]}]}'
```

The key goes in `x-goog-api-key` (what the SDK sends) or in
`Authorization: Bearer`. A key in the URL (`?key=`) is refused with 401: URLs
end up in logs.

**Max length.** Set a max length (`max_tokens` / `max_completion_tokens` / `max_output_tokens` / `maxOutputTokens`). Without it we hold the model's full maximum; if your spend limit can't cover that, we lower the max to what it can.

## Gemini 4 thinking

Set `generationConfig.thinkingConfig.thinkingLevel` to `LOW`, `MEDIUM`, or
`HIGH` to control how much reasoning a Gemini 4 model uses. Reasoning tokens
count toward `maxOutputTokens` and are billed at the model's output rate.
Check the model's page or `GET /v1/models` for its output limit and token
prices. [Google's thinking guide](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/thinking)

## Streaming

`streamGenerateContent?alt=sse` (the SDK's `generate_content_stream`) sends
`data:` chunks in Gemini's shape. The last chunk has `usageMetadata`, with
`cost_usd`.

```python
from google import genai
import os

client = genai.Client(
    api_key=os.environ["INVIDEO_API_KEY"],
    http_options={"base_url": "https://platform-api.invideo.io", "api_version": "v1beta"},
)

for chunk in client.models.generate_content_stream(model="gemini-4-carbon", contents="Write a haiku about soup."):
    print(chunk.text, end="", flush=True)
```

## Audio and video

Send audio or video as `inlineData` (base64, up to 20 MB in all) or an `https`
`fileData`, next to your text:

```python
from google import genai
from google.genai import types
import os

client = genai.Client(
    api_key=os.environ["INVIDEO_API_KEY"],
    http_options={"base_url": "https://platform-api.invideo.io", "api_version": "v1beta"},
)

audio = open("talk.mp3", "rb").read()
answer = client.models.generate_content(
    model="gemini-4-carbon",
    contents=[types.Part.from_bytes(data=audio, mime_type="audio/mpeg"), "Summarise this recording."],
)
print(answer.text)
```

Audio tokens (a video's sound included, about 25 tokens per second) cost the
model's audio price, `audio_input_per_m` in `GET /v1/models`; a video's frames
cost the input price. Only Gemini models take audio and video.

## Answer

```json
{
  "responseId": "0193b0c4-...",
  "modelVersion": "gemini-4-carbon",
  "candidates": [{"content": {"role": "model", "parts": [{"text": "SimmerCut"}]}, "finishReason": "STOP"}],
  "usageMetadata": {
    "promptTokenCount": 9,
    "candidatesTokenCount": 4,
    "cachedContentTokenCount": 0,
    "thoughtsTokenCount": 0,
    "totalTokenCount": 13,
    "cost_usd": "0.000004"
  }
}
```

- `responseId` is the request's id in Logs (also the `x-request-id` header).
- `finishReason`: `STOP` (finished normally), `MAX_TOKENS` (it hit
  `maxOutputTokens`), `SAFETY` (blocked).

## Errors

Gemini's shape, so the SDK raises `genai.errors.APIError` with the status. Our
code is in `error.code_name`:

```json
{"error": {"code": 404, "message": "...", "status": "NOT_FOUND", "code_name": "model_not_found"}}
```

Refused with `unsupported_parameter` (HTTP 400): `cachedContent`, `fileData`
with `gs://` or File API links (send `inlineData`, or an `https` link), and the
`googleSearch`, `codeExecution` and `urlContext` tools. `GET /v1beta/models`
lists models in Gemini's shape. All codes: [Errors](/docs/errors).
