Skip to navigation

Google GenAI (gateway)

Route Google Gen AI SDK calls through the Respan gateway. Only your RESPAN_API_KEY is needed — no separate GOOGLE_API_KEY required.

Setup

1

Install packages

pip install google-genai
2

Set environment variables

export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"

No GOOGLE_API_KEY needed — the Respan gateway handles provider authentication.

3

Point the Gen AI client to the Respan gateway

import os
from google import genai
client = genai.Client(
api_key=os.environ["RESPAN_API_KEY"],
http_options={"base_url": "https://api.respan.ai/api/google/gemini"},
)
response = client.models.generate_content(
model="gemini-3.8-flash",
contents="Hello, world!",
)
print(response.text)

Switch models

Change the model parameter to use different Gemini models through the same gateway.

response = client.models.generate_content(model="gemini-3.8-flash", contents="Hello")
response = client.models.generate_content(model="gemini-3.5-flash-lite", contents="Hello")
response = client.models.generate_content(model="gemini-pro-latest", contents="Hello")

See the full model list.

Advanced configuration

GenerateContentConfig supports system instructions, sampling parameters, tools, safety settings, and structured output.

from google.genai import types
config = types.GenerateContentConfig(
system_instruction="You are a helpful assistant.",
temperature=0.7,
top_p=0.95,
top_k=40,
max_output_tokens=1024,
safety_settings=[
types.SafetySetting(
category=types.HarmCategory.HARM_CATEGORY_HATE_SPEECH,
threshold=types.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
),
],
)
response = client.models.generate_content(
model="gemini-3.8-flash",
contents="What is the capital of France?",
config=config,
)