> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://doc.enterpriserouter.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://doc.enterpriserouter.com/_mcp/server.

# Gemini (Native Mode)

## Setup

Install the Google Generative AI SDK:

```bash
pip install google-generativeai
```

Configure the client to use your gateway:

```python
import google.generativeai as genai

genai.configure(
    api_key="sk-proxy-YOUR_KEY_HERE",
    transport="rest",
    client_options={"api_endpoint": "https://api.enterpriserouter.com/gemini"}
)
```

## Basic generation

```python
model = genai.GenerativeModel("gemini-2.5-flash")

response = model.generate_content("Explain quantum computing in one paragraph.")

print(response.text)
```

## Streaming

```python
model = genai.GenerativeModel("gemini-2.5-flash")

response = model.generate_content(
    "Write a haiku about APIs.",
    stream=True
)

for chunk in response:
    print(chunk.text, end="")
```

## Multi-turn conversation

```python
model = genai.GenerativeModel("gemini-2.5-flash")
chat = model.start_chat()

response = chat.send_message("What's the capital of France?")
print(response.text)

response = chat.send_message("What's its population?")
print(response.text)
```

## Using REST directly

If you prefer raw HTTP, Gemini's REST API works through the gateway. The model name goes in the URL path:

```bash
curl -X POST "https://api.enterpriserouter.com/gemini/v1beta/models/gemini-2.5-flash:generateContent" \
  -H "x-goog-api-key: sk-proxy-YOUR_KEY_HERE" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {"parts": [{"text": "Hello, how are you?"}]}
    ]
  }'
```

For streaming, use the `streamGenerateContent` method with `alt=sse`:

```bash
curl -X POST "https://api.enterpriserouter.com/gemini/v1beta/models/gemini-2.5-flash:streamGenerateContent?alt=sse" \
  -H "x-goog-api-key: sk-proxy-YOUR_KEY_HERE" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {"parts": [{"text": "Write a short story."}]}
    ]
  }'
```

## Notes

* **Model in URL path**: Unlike OpenAI and Anthropic, Gemini identifies the model in the URL path (`/models/{model}:generateContent`), not in the request body.
* **Auth header**: The Google SDK sends your proxy key as `x-goog-api-key`, which the gateway accepts. You can also use `Authorization: Bearer` or `x-api-key` if making raw HTTP requests.

## Supported models

* `gemini-2.5-pro`, `gemini-2.5-flash`, `gemini-2.5-flash-lite`
* `gemini-3.1-pro-preview`, `gemini-3-flash-preview`

New Gemini models work automatically.