> ## Documentation Index
> Fetch the complete documentation index at: https://docs.promptguard.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Gemini

> Scan Gemini traffic through the PromptGuard proxy with any OpenAI client, or with the SDK auto-instrumentation

Two ways in: send Gemini requests to the proxy in OpenAI's format, or call `init()` and keep Google's client as it is ([auto-instrumentation](https://docs.promptguard.co/integrations/auto-instrumentation.md) patches both `google-genai` and the deprecated `google-generativeai`).

## Proxy

> [!NOTE]
>
> **Proxy Base URL:** `https://api.promptguard.co/api/v1`
>
> Point your LLM SDK's `base_url` / `baseURL` to this endpoint. Your existing provider API key goes in the `Authorization` header as usual; add your PromptGuard key via `X-API-Key`.

Every model id starting `gemini-` goes to Google's Gemini API. You send an OpenAI-style chat completion; PromptGuard translates it into a Gemini `generateContent` call and translates the reply back into OpenAI's shape, so any OpenAI client works. Google's own SDKs do not speak this format, so for them use auto-instrumentation instead.

Send your Google AI Studio API key in `Authorization`. PromptGuard forwards it to Google as the `x-goog-api-key` header Google expects.

```python Python theme={"system"}
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.promptguard.co/api/v1",
    api_key=os.environ["GEMINI_API_KEY"],  # forwarded to Google
    default_headers={"X-API-Key": os.environ["PROMPTGUARD_API_KEY"]},
)

response = client.chat.completions.create(
    model="gemini-2.5-flash",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)
```

```typescript Node.js theme={"system"}
import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://api.promptguard.co/api/v1',
  apiKey: process.env.GEMINI_API_KEY, // forwarded to Google
  defaultHeaders: { 'X-API-Key': process.env.PROMPTGUARD_API_KEY },
});

const response = await client.chat.completions.create({
  model: 'gemini-2.5-flash',
  messages: [{ role: 'user', content: 'Hello!' }],
});
console.log(response.choices[0].message.content);
```

```bash cURL theme={"system"}
curl https://api.promptguard.co/api/v1/chat/completions \
  -H "X-API-Key: $PROMPTGUARD_API_KEY" \
  -H "Authorization: Bearer $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "gemini-2.5-flash", "messages": [{"role": "user", "content": "Hello!"}]}'
```

The translation calls `generateContent`, Google's non-streaming method, so send these requests without `stream`.

To keep the Google key out of your application, [store it as a provider key](https://docs.promptguard.co/gateway/provider-keys.md) under `gemini`.

## Auto-instrumentation

```python Python theme={"system"}
import promptguard
promptguard.init()  # reads PROMPTGUARD_API_KEY

from google import genai
client = genai.Client()  # talks to Google directly; generate_content is scanned first
```

```typescript Node.js theme={"system"}
import { init } from 'promptguard-sdk';
import { GoogleGenAI } from '@google/genai';

init(); // reads PROMPTGUARD_API_KEY
const ai = new GoogleGenAI({}); // talks to Google directly; models.generateContent is scanned first
```

With `google-genai` a redact decision rewrites the prompt and the system instruction is scanned. With the deprecated `google-generativeai` neither is possible, so in enforce mode a redact decision blocks the call instead.

## Next steps

> [card] [Auto-instrumentation](https://docs.promptguard.co/integrations/auto-instrumentation.md)
>
> Which provider calls `init()` patches, and which it does not

> [card] [Provider keys](https://docs.promptguard.co/gateway/provider-keys.md)
>
> Store your provider credentials once, forwarded server-side

> [card] [Fallback models](https://docs.promptguard.co/gateway/fallback-models.md)
>
> Models to try when the one you asked for is down


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.