For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
DashboardSign Up
  • Getting Started
    • Welcome
    • Quick Start
    • Authentication
  • Native Mode
    • Overview
    • OpenAI
    • Anthropic
    • Gemini
  • Unified Mode
    • Overview
    • Python
    • TypeScript
    • cURL
  • Platform
    • Key Management
    • Rate Limits & Budgets
    • Usage & Billing
    • Error Reference
  • API Reference
DashboardSign Up
On this page
  • Setup
  • Basic generation
  • Streaming
  • Multi-turn conversation
  • Using REST directly
  • Notes
  • Supported models
Native Mode

Gemini (Native Mode)

Use the Google Gemini API with Gateway AI
Was this page helpful?
Edit this page
Previous

Unified Mode

One SDK for every provider
Next
Built with

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://api.trygateway.ai/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://api.trygateway.ai/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.trygateway.ai/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.