Skip to main content

What changes in your code

Two settings change: the base URL points at the gateway, and the API key is a virtual key. The request body, streaming, tools and every other SDK feature stay the same. Name the model as provider/model on the OpenAI-shaped and Anthropic-shaped routes; the Gemini passthrough at /v1beta names the model in Google’s own form. See Model naming.

OpenAI SDK

The same client serves client.responses, client.embeddings, client.audio.speech and client.audio.transcriptions. With an Anthropic or Gemini model name the gateway translates the chat request to the provider’s format.

Anthropic SDK

Vercel AI SDK

createOpenAI also takes headers: { ... } for headers that are the same on every request.

LangChain.js

The gateway records one gen_ai.<request type> span per request in the trace project of the virtual key. Send a W3C traceparent header and the gateway nests that span under your span. Without it, each request is its own trace. Any OpenTelemetry-instrumented application has the current context. Inject it into the request headers, per request, inside the span you want the gateway span under:
The LangWatch TypeScript SDK uses OpenTelemetry, so the same code works inside a langwatch span. Do not also instrument the OpenAI client for calls that go through the gateway: the gateway already records the span with the model, the tokens and the cost.

Headers you can send

Pass them per request in the second argument of the OpenAI SDK methods, { headers: { ... } }. The gateway removes them before it forwards the request to the provider. See Billing and spend events.

Read the response headers

Manage keys and budgets from TypeScript

The langwatch package wraps the management routes: VirtualKeysApiService, GatewayBudgetsApiService and langwatch.spendEvents on a LangWatch client, with a LangWatch API key. See Virtual keys and Billing and spend events.

Self-hosted gateway

Replace the host with your gateway’s URL. Everything else is the same.

In the browser

The gateway sends no CORS headers on /v1, and a virtual key in browser code is visible to every visitor. Call the gateway from your server.

Troubleshooting

See Errors for every error code.
Last modified on September 6, 2026