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

# Google Gemini Integration

> Route Google Gemini API calls through CostHawk to track costs

<Warning>
  A wrapped key only works against the CostHawk proxy. Do not send `ch_sk_...` directly to Google's native endpoint.
</Warning>

<Info>
  If you are not sure whether you have a wrapped key or a CostHawk access token, read <a href="/integrations/wrapped-keys">Wrapped Keys</a> first.
</Info>

## Quick Setup

<Steps>
  <Step title="Create a wrapped key">
    Go to [Dashboard → Integrations](https://costhawk.ai/dashboard/wrapped-keys), click **Create API Key**, select **Google**, and paste your Google AI API key.
  </Step>

  <Step title="Copy your wrapped key">
    Copy the `ch_sk_...` key that CostHawk generates.
  </Step>

  <Step title="Update your code">
    Change the base URL and API key as shown below.
  </Step>
</Steps>

## Proxy URL

```
POST https://costhawk.ai/api/proxy/google
```

This replaces `https://generativelanguage.googleapis.com/v1beta/models/{model}:generateContent`.

## Code Examples

### Python

```python theme={null}
import requests

response = requests.post(
    "https://costhawk.ai/api/proxy/google",
    headers={
        "Content-Type": "application/json",
        "Authorization": "Bearer ch_sk_your_wrapped_key_here",
    },
    json={
        "model": "gemini-2.0-flash",
        "contents": [
            {
                "parts": [
                    {"text": "Hello, Gemini!"}
                ]
            }
        ]
    }
)

data = response.json()
print(data["candidates"][0]["content"]["parts"][0]["text"])
```

### Node.js

```javascript theme={null}
const response = await fetch("https://costhawk.ai/api/proxy/google", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer ch_sk_your_wrapped_key_here",
  },
  body: JSON.stringify({
    model: "gemini-2.0-flash",
    contents: [
      {
        parts: [
          { text: "Hello, Gemini!" }
        ]
      }
    ]
  }),
});

const data = await response.json();
console.log(data.candidates[0].content.parts[0].text);
```

### curl

```bash theme={null}
curl -X POST https://costhawk.ai/api/proxy/google \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ch_sk_your_wrapped_key_here" \
  -d '{
    "model": "gemini-2.0-flash",
    "contents": [
      {
        "parts": [
          {"text": "Hello, Gemini!"}
        ]
      }
    ]
  }'
```

<Note>
  Include the `model` field in the request body. CostHawk uses it to construct the correct Google API URL (`/v1beta/models/{model}:generateContent`).
</Note>

## Supported Models

All Google Gemini models work through the proxy, including:

* `gemini-2.0-flash`
* `gemini-2.0-pro`
* `gemini-1.5-flash`
* `gemini-1.5-pro`

## Supported Endpoint

The proxy supports the **generateContent** endpoint. Pass the model name in the request body and CostHawk handles the URL routing.
