---
title: "Google GenAI (gateway)"
description: "Set up Google Gen AI with the Respan gateway."
---

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

Paste this into your coding agent:

```text
Help me set up the Respan gateway with the Google GenAI integration.
Follow https://www.respan.ai/docs/integrations/gateway/google-gen-ai.md
```

## Setup

<Steps>
<Step title="Install packages">

<Tabs>
<Tab title={"Python"}>

```bash
pip install google-genai
```

</Tab>
<Tab title={"TypeScript"}>

```bash
npm install @google/genai
```

</Tab>
</Tabs>

</Step>

<Step title="Set environment variables">

```bash
export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
```

No `GOOGLE_API_KEY` needed. The Respan gateway handles provider authentication.

</Step>

<Step title="Point the Gen AI client to the Respan gateway">

<Tabs>
<Tab title={"Python"}>

```python
import os
from google import genai

client = genai.Client(
    api_key=os.environ["RESPAN_API_KEY"],
    http_options={"base_url": "https://gateway.respan.ai"},
)

response = client.models.generate_content(
    model="gemini-3.8-flash",
    contents="Hello, world!",
)
print(response.text)
```

</Tab>
<Tab title={"TypeScript"}>

```typescript
import { GoogleGenAI } from "@google/genai";

const genAI = new GoogleGenAI({
  apiKey: process.env.RESPAN_API_KEY,
  httpOptions: { baseUrl: "https://gateway.respan.ai" },
});

const result = await genAI.models.generateContent({
  model: "gemini-3.8-flash",
  contents: [{ role: "user", parts: [{ text: "Hello, world!" }] }],
});
console.log(result.text);
```

</Tab>
</Tabs>

</Step>
</Steps>

## Switch models

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

```python
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](https://platform.respan.ai/platform/models).

## Advanced configuration

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

```python
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,
)
```
