> ## 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](/integrations/auto-instrumentation) 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`.
</Note>

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.

<CodeGroup>
  ```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!"}]}'
  ```
</CodeGroup>

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](/gateway/provider-keys) under `gemini`.

## Auto-instrumentation

```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
```

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.


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