# Gemini protocol

> The gateway accepts native Gemini generateContent paths; point google-genai's base_url at the gateway.

The native Gemini protocol uses `POST /v1beta/models/{model}:generateContent` (and
`:streamGenerateContent` for streaming).

## curl

```bash
curl "https://api.tokrouter.dev/v1beta/models/gemini-3.8-flash:generateContent" \
  -H "x-goog-api-key: $TOKROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{"parts": [{"text": "Explain SSE in one sentence"}]}]
  }'
```

## google-genai (Python)

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

client = genai.Client(
    api_key=os.environ["TOKROUTER_API_KEY"],
    http_options=types.HttpOptions(base_url="https://api.tokrouter.dev"),
)

resp = client.models.generate_content(
    model="gemini-3.8-flash",
    contents="Explain SSE in one sentence",
)
print(resp.text)
```

## google-genai (TypeScript)

```ts

const ai = new GoogleGenAI({
  apiKey: process.env.TOKROUTER_API_KEY!,
  httpOptions: { baseUrl: 'https://api.tokrouter.dev' },
})

const resp = await ai.models.generateContent({
  model: 'gemini-3.8-flash',
  contents: 'Explain SSE in one sentence',
})
console.log(resp.text)
```

<Callout type="info" title="Or just use the OpenAI protocol">
If you prefer, call the same model through `/v1/chat/completions` with `model: "gemini-3.8-flash"` and
an OpenAI-shaped body. Both routes bill against the same key.
</Callout>

## DashScope (Alibaba)

Alibaba's native path lives under `/v1` with the official `/api` prefix **removed**:

```bash
curl https://api.tokrouter.dev/v1/services/aigc/text-generation/generation \
  -H "Authorization: Bearer $TOKROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3.8-max",
    "input": {"messages": [{"role": "user", "content": "Hello"}]},
    "parameters": {"result_format": "message"}
  }'
```

The official `https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation` maps to
`https://api.tokrouter.dev/v1/services/aigc/text-generation/generation`. Routing is decided by the
`model` field, so you do not change paths per vendor.
