Native Mode

Gemini (Native Mode)

Use the Google Gemini API with Enterprise Router

Setup

Install the Google Generative AI SDK:

$pip install google-generativeai

Configure the client to use your gateway:

1import google.generativeai as genai
2
3genai.configure(
4 api_key="sk-proxy-YOUR_KEY_HERE",
5 transport="rest",
6 client_options={"api_endpoint": "https://gateway.example.com/gemini"}
7)

Basic generation

1model = genai.GenerativeModel("gemini-2.5-flash")
2
3response = model.generate_content("Explain quantum computing in one paragraph.")
4
5print(response.text)

Streaming

1model = genai.GenerativeModel("gemini-2.5-flash")
2
3response = model.generate_content(
4 "Write a haiku about APIs.",
5 stream=True
6)
7
8for chunk in response:
9 print(chunk.text, end="")

Multi-turn conversation

1model = genai.GenerativeModel("gemini-2.5-flash")
2chat = model.start_chat()
3
4response = chat.send_message("What's the capital of France?")
5print(response.text)
6
7response = chat.send_message("What's its population?")
8print(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:

$curl -X POST "https://gateway.example.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:

$curl -X POST "https://gateway.example.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 gateway uses the x-goog-api-key header for Gemini authentication.

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.