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.
DiscordPlatform
DocumentationIntegrationsAPI referenceSDKsChangelog
DocumentationIntegrationsAPI referenceSDKsChangelog
    • Overview
  • Tracing
  • Gateway
      • OpenAI SDK
      • Instructor
      • Anthropic SDK
      • Google GenAI
      • LiteLLM
      • RubyLLM
      • Vertex AI
      • AWS Bedrock
      • Cohere
      • Groq
      • Mistral AI
      • Ollama
      • Watsonx
      • Together AI
      • Aleph Alpha
      • HuggingFace
      • Replicate
      • SageMaker
      • Respan API
  • Others
  • Migrating
    • Braintrust
    • Portkey
    • Langfuse
LogoLogo
DiscordPlatform
On this page
  • Setup
  • Switch models
  • Advanced configuration
GatewayLLM SDKs

Google GenAI (gateway)

Was this page helpful?
Previous

LiteLLM (gateway)

Next
Built with

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 respan-ai opentelemetry-instrumentation-google-generativeai 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

1import os
2from google import genai
3
4client = genai.Client(
5 api_key=os.environ["RESPAN_API_KEY"],
6 http_options={"base_url": "https://api.respan.ai/api/google/gemini"},
7)
8
9response = client.models.generate_content(
10 model="gemini-2.5-flash",
11 contents="Hello, world!",
12)
13print(response.text)

Switch models

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

1response = client.models.generate_content(model="gemini-2.5-flash", contents="...")
2response = client.models.generate_content(model="gemini-2.0-flash-exp", contents="...")
3response = client.models.generate_content(model="gemini-1.5-pro", contents="...")

See the full model list.

Advanced configuration

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

1from google.genai import types
2
3config = types.GenerateContentConfig(
4 system_instruction="You are a helpful assistant.",
5 temperature=0.7,
6 top_p=0.95,
7 top_k=40,
8 max_output_tokens=1024,
9 safety_settings=[
10 types.SafetySetting(
11 category=types.HarmCategory.HARM_CATEGORY_HATE_SPEECH,
12 threshold=types.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
13 ),
14 ],
15)
16
17response = client.models.generate_content(
18 model="gemini-2.5-flash",
19 contents="What is the capital of France?",
20 config=config,
21)