What changes in your client
Any client that lets you set an OpenAI base URL and an API key works with the gateway. Set the base URL tohttps://gateway.langwatch.ai/v1 and send the virtual key as Authorization: Bearer. The request body, streaming and tools stay the same. Name the model as provider/model; see Model naming.
The virtual key (
vk-lw-...) is not your LangWatch API key. For the SDKs, see the TypeScript SDK, the Python SDK and the Go SDK.
Chat completions
"stream": true to stream the answer as server-sent events. Use curl -N so curl does not buffer the frames:
text/event-stream, one data: frame per chunk, ending with data: [DONE]. See Streaming.
Messages (Anthropic shape)
Authorization: Bearer works in place of X-Api-Key. The gateway reads Authorization: Bearer, X-Api-Key, X-Goog-Api-Key and Xi-Api-Key; see Virtual keys.
Check it worked
Run the chat completions request. It returns a JSON body with the model’s answer. Then open the project the virtual key traces to in LangWatch: the gateway’sgen_ai.<request type> span appears in the traces list within a few seconds, as its own trace, with the model, the tokens and the cost.
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.
00-<trace id>-<span id>-<flags>, with a 32-character trace id and a 16-character span id in hexadecimal. In an instrumented application, inject the current context rather than writing the value by hand; see the OpenTelemetry samples in the TypeScript SDK, the Python SDK and the Go SDK.
Headers you can send
The gateway removes them before it forwards the request to the provider. See Billing and spend events.
Read the response headers
Add-i to print the response headers before the body:
The full list is on Chat Completions.
Self-hosted gateway
Replace the host with your gateway’s URL, for examplehttps://gateway.acme.internal/v1. Everything else is the same.
In the browser
The gateway sends no CORS headers on/v1 unless the operator allows origins, 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.