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 asprovider/model on the OpenAI-shaped and Anthropic-shaped routes; see Model naming.
OpenAI SDK
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
Google GenAI SDK
/v1beta, which names the model in Google’s own form. Write gemini-2.5-flash, not gemini/gemini-2.5-flash. The provider/model form applies to the OpenAI-shaped and Anthropic-shaped routes.
LangChain
ChatAnthropic takes base_url="https://gateway.langwatch.ai" and the virtual key as api_key.
LlamaIndex
Link the gateway span to your trace
The gateway records onegen_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 already has the current context. Inject it into the request headers:
trace_headers() per request, inside the span you want the gateway span under. default_headers on the client is read once and would pin the first span.
The LangWatch Python SDK uses OpenTelemetry, so the same code works inside langwatch.trace() or a @langwatch.span() function. Do not also autotrack 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 with
extra_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 Python
The LangWatch Python SDK wraps the management routes:langwatch.virtual_keys, langwatch.gateway_budgets, langwatch.spend_events and langwatch.webhooks. They take a LangWatch API key through langwatch.setup(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.Troubleshooting
See Errors for every error code.