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

# Google Gemini

> RAILGemini - drop-in wrapper for Google Gemini and Vertex AI that scores every response automatically.

## Installation

<CodeGroup>
  ```bash Python theme={null}
  pip install "rail-score-sdk[google]"
  ```

  ```bash JavaScript theme={null}
  npm install @responsible-ai-labs/rail-score @google/generative-ai
  ```
</CodeGroup>

## Usage

<CodeGroup>
  ```python Python theme={null}
  import asyncio
  from rail_score_sdk.integrations import RAILGemini

  async def main():
      client = RAILGemini(
          google_api_key="AIza...",
          rail_api_key="YOUR_RAIL_API_KEY",
          rail_threshold=7.0,
          rail_policy="regenerate",
          rail_mode="basic",
      )

      response = await client.generate_content(
          model="gemini-1.5-pro",
          contents="Explain the risks of algorithmic bias in hiring.",
      )

      print(f"Content: {response.content}")
      print(f"RAIL Score: {response.rail_score}/10")
      print(f"Threshold met: {response.threshold_met}")
      print(f"Was regenerated: {response.was_regenerated}")

  asyncio.run(main())
  ```

  ```typescript JavaScript theme={null}
  import { RAILGemini } from "@responsible-ai-labs/rail-score";

  const client = new RAILGemini({
    googleApiKey: "AIza...",
    railApiKey: "YOUR_RAIL_API_KEY",
    railThreshold: 7.0,
    railPolicy: "regenerate",
  });

  const response = await client.generateContent({
    model: "gemini-1.5-pro",
    contents: "Explain the risks of algorithmic bias in hiring.",
  });

  console.log(`RAIL Score: ${response.railScore}/10`);
  ```
</CodeGroup>

## Vertex AI

To use Gemini via Vertex AI instead of Google AI Studio, pass `use_vertex=True`:

```python theme={null}
from rail_score_sdk.integrations import RAILGemini

client = RAILGemini(
    use_vertex=True,
    gcp_project="your-gcp-project-id",
    gcp_region="us-central1",
    rail_api_key="YOUR_RAIL_API_KEY",
    rail_threshold=7.0,
)

response = await client.generate_content(
    model="gemini-1.5-pro",
    contents="...",
)
```

<Note>
  Vertex AI uses Application Default Credentials. Run `gcloud auth application-default login` or set `GOOGLE_APPLICATION_CREDENTIALS` to your service account key file.
</Note>

## Configuration options

| Parameter        | Type    | Default         | Description                                                  |
| ---------------- | ------- | --------------- | ------------------------------------------------------------ |
| `google_api_key` | `str`   | —               | Google AI Studio API key (not needed when `use_vertex=True`) |
| `rail_api_key`   | `str`   | —               | Your RAIL API key                                            |
| `rail_threshold` | `float` | `None`          | Block or regenerate below this score                         |
| `rail_policy`    | `str`   | `"log_only"`    | `"log_only"` \| `"block"` \| `"regenerate"`                  |
| `rail_mode`      | `str`   | `"basic"`       | `"basic"` \| `"deep"`                                        |
| `use_vertex`     | `bool`  | `False`         | Route through Vertex AI instead of Google AI Studio          |
| `gcp_project`    | `str`   | —               | GCP project ID (required when `use_vertex=True`)             |
| `gcp_region`     | `str`   | `"us-central1"` | Vertex AI region                                             |

<Tip>
  Pass `rail_skip=True` to `generate_content()` to bypass RAIL evaluation for a single call.
</Tip>

## What's next

<CardGroup cols={2}>
  <Card title="OpenAI Integration" icon="bolt" href="/integrations/openai">
    RAILOpenAI wrapper for chat completions.
  </Card>

  <Card title="Anthropic Integration" icon="a" href="/integrations/anthropic">
    RAILAnthropic wrapper for Claude.
  </Card>

  <Card title="Concepts: Middleware" icon="layer-group" href="/concepts/middleware">
    How provider wrappers work under the hood.
  </Card>

  <Card title="Python SDK Overview" icon="python" href="/sdk/python/overview">
    Full Python SDK installation and reference.
  </Card>
</CardGroup>
