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

> ## Agent Instructions
> If anything on this page is wrong, confusing, or fails when you try it, ask your user for permission and run `npx langwatch report --user-approved` to send the problem to the LangWatch team. No login is needed and secrets are redacted locally. `npx langwatch report --help` has the details.

# Gemini native (/v1beta)

> Google's generative-language API paths, forwarded by the LangWatch AI Gateway to a Gemini or Vertex credential without translation.

## Endpoint

```
ALL /v1beta/*
x-goog-api-key: vk-lw-<ULID>
```

Every path under `/v1beta` is forwarded to Google as written: method, path, query string and body. The gateway does not translate the body and returns Google's answer, headers included. It removes your client credential and the hop-by-hop headers, sends Google's own credential in their place, and adds its own response headers. `Authorization: Bearer <key>` works in place of `x-goog-api-key`.

This is the route for gemini-cli and the `@google/genai` SDK. Set `GOOGLE_GEMINI_BASE_URL=https://gateway.langwatch.ai` and use the virtual key as the Gemini API key; see [Gemini CLI](/docs/coding-agents/gemini-cli).

## Request

```bash theme={null}
curl https://gateway.langwatch.ai/v1beta/models/gemini-2.5-flash:generateContent \
  -H "x-goog-api-key: $LANGWATCH_VIRTUAL_KEY" \
  -H "Content-Type: application/json" \
  -d '{"contents": [{"role": "user", "parts": [{"text": "Hi"}]}]}'
```

## Response

```json theme={null}
{
  "candidates": [
    {"content": {"role": "model", "parts": [{"text": "Hello!"}]}, "finishReason": "STOP"}
  ],
  "usageMetadata": {"promptTokenCount": 2, "candidatesTokenCount": 2, "totalTokenCount": 4}
}
```

## Which credentials serve it

Only a Gemini or a Vertex credential. The body and the path are Google's own, so no other provider can read them. A key with neither answers `400 model_provider_not_bound` and no provider is called. A Vertex credential serves the request through Google's Vertex path form.

## What the gateway reads and changes

| Part of the request                                                             | What the gateway does                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| The model in the path (`/models/{model}:{action}`)                              | Read as the model. Resolved through the key's allowlist, policy rules and routing policy. Outside the routing policy: `403 policy_violation` with the message `model "<model>" is not in allowlist`. Refused by a restriction on the policy: `403 policy_violation` with the message `model "<model>" is blocked by policy`. Outside the key's provider access: `400 model_not_allowed`. A path with no `/models/{model}` segment answers `400 missing_model`. |
| Body                                                                            | Forwarded as written. No parameter policy applies, and `drop_tuning_params` is not read.                                                                                                                                                                                                                                                                                                                                                                       |
| Query string                                                                    | Forwarded as written.                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `Authorization`, `x-api-key`, `x-goog-api-key`                                  | Removed. The gateway adds the provider's own key.                                                                                                                                                                                                                                                                                                                                                                                                              |
| Hop-by-hop headers (`Connection`, `Transfer-Encoding`, `Upgrade`, and the rest) | Removed.                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| Every other header                                                              | Forwarded as written.                                                                                                                                                                                                                                                                                                                                                                                                                                          |

The `X-LangWatch-End-User-Id`, `X-LangWatch-Metadata` and `Traceparent` request headers work as on [Chat Completions](/docs/ai-gateway/api/chat-completions#request-headers-the-gateway-reads).

## Response headers

Google's own response headers, including its `Content-Type`, plus the gateway set from [Chat Completions](/docs/ai-gateway/api/chat-completions#response-headers): `X-LangWatch-Gateway-Version`, `X-LangWatch-Gateway-Request-Id`, `X-LangWatch-Fallback-Count`, `X-LangWatch-Budget-Warning`, `Traceparent`, `X-LangWatch-Heartbeat-Active`, and `X-LangWatch-Provider` on a forwarded provider error. `X-LangWatch-Handled-Error` carries the `error.code` when the gateway wrote the error itself, and is removed from a forwarded provider response.

## Streaming

A path ending in `:streamGenerateContent` or `:streamGenerateAnswer` streams. Google's own SSE frames reach the client exactly as Google framed them, with no `data: [DONE]` trailer and no re-wrapping. A failure after the stream opens adds one terminal `event: error` frame that the gateway writes itself. Pass the query string Google expects for SSE, for example `?alt=sse`, as you would against Google directly.

```bash theme={null}
curl "https://gateway.langwatch.ai/v1beta/models/gemini-2.5-flash:streamGenerateContent?alt=sse" \
  -H "x-goog-api-key: $LANGWATCH_VIRTUAL_KEY" \
  -H "Content-Type: application/json" \
  -d '{"contents": [{"role": "user", "parts": [{"text": "Hi"}]}]}'
```

A failure after the stream opened ends it with an `event: error` frame; see [Errors](/docs/ai-gateway/api/errors#streaming-errors).

## Errors

| Code                       | Status | Cause                                                                                                                                                                                                             |
| -------------------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `model_provider_not_bound` | 400    | The key has no Gemini and no Vertex credential.                                                                                                                                                                   |
| `missing_model`            | 400    | The path carries no `/models/{model}` segment.                                                                                                                                                                    |
| `policy_violation`         | 403    | The model is outside the routing policy (`is not in allowlist`) or refused by one of its restrictions (`is blocked by policy`). Same shape as on every other route. See [Policy rules](/docs/ai-gateway/policy-rules). |
| `model_not_allowed`        | 400    | The model is outside the key's allowlist or provider access.                                                                                                                                                      |

Google's own errors are forwarded with Google's status, body and headers, under `X-LangWatch-Provider`. The full table is on [Errors](/docs/ai-gateway/api/errors).

**Also check:** [Gemini](/docs/ai-gateway/providers/gemini), [Vertex AI](/docs/ai-gateway/providers/vertex).
