Skip to contentSkip to page list

Docs

Gemini native (/v1beta)

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

On this page

Endpoint

example.txtText
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.

Request

example.shBash
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

example.jsonJSON
{  "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 requestWhat 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.
BodyForwarded as written. No parameter policy applies, and drop_tuning_params is not read.
Query stringForwarded as written.
Authorization, x-api-key, x-goog-api-keyRemoved. The gateway adds the provider's own key.
Hop-by-hop headers (Connection, Transfer-Encoding, Upgrade, and the rest)Removed.
Every other headerForwarded as written.

The X-LangWatch-End-User-Id, X-LangWatch-Metadata and Traceparent request headers work as on Chat Completions.

Response headers

Google's own response headers, including its Content-Type, plus the gateway set from Chat Completions: 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.

example.shBash
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.

Errors

CodeStatusCause
model_provider_not_bound400The key has no Gemini and no Vertex credential.
missing_model400The path carries no /models/{model} segment.
policy_violation403The 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.
model_not_allowed400The 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.

Also check: Gemini, Vertex AI.

Documentation