Skip to navigation
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:

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

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

Streaming

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

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:

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:

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.