This walkthrough takes you from zero to a traced, budget-gated LLM response.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.
You’ll need a LangWatch account, an organisation admin or project admin role, and at least one model provider (OpenAI, Anthropic, Azure OpenAI, Bedrock, Vertex, or Gemini) configured at Settings → Model Providers. If you haven’t set one up yet, start there — the AI Gateway reuses those credentials.
Python / TypeScript SDK
Drop-in for the OpenAI / Anthropic SDKs — swap
base_url and api_key.Use it from your coding assistant
Wire Claude Code, Codex, OpenCode, Cursor, or Aider through the gateway.
Core concepts
Virtual keys, budgets, provider bindings, cache rules, fallback chains.
API reference
OpenAI-compatible
/v1/chat/completions + Anthropic-shape /v1/messages.1. Create a virtual key
- Open AI Gateway → Virtual Keys in the LangWatch app.
- Click New virtual key.
- Name it — e.g.
my-first-vk. - Select which provider credentials it may use. The first one becomes the primary; later ones become the fallback chain.
- (Optional) Attach a budget, pick a cache mode, attach guardrails.
- Click Create.
lw_vk_live_01HZX9K3M…) is displayed exactly once. Copy it now and store it in a secret manager. After you dismiss the dialog, LangWatch can never show it again — only the prefix lw_vk_live_01HZX9 remains visible in the list.
2. Call the gateway (OpenAI-compatible)
Usingcurl:
Using the OpenAI SDKs
Python:Anthropic-compatible (Claude SDK, Claude Code)
3. See the trace in LangWatch
Within ~30 seconds the request appears in the project the virtual key belongs to:- Messages view shows the prompt, response, tokens, cost, provider, cache outcome, and the full trace.
- Analytics aggregates across all VKs in the project.
- Evaluations can run on the traffic passing through the gateway.
| Attribute | Meaning |
|---|---|
langwatch.vk_id | Virtual key id. |
langwatch.project_id | Owning project. |
langwatch.team_id | Owning team. |
langwatch.org_id | Owning organisation. |
langwatch.principal_id | User or service account that made the call. |
gen_ai.usage.cache_read.input_tokens / gen_ai.usage.cache_creation.input_tokens | Cache economics (OTel GenAI semconv; zero when cache bypassed). |
langwatch.fallback.attempt | 0 on primary success, N for fallback attempts. |
4. Add a budget
Budgets live one level up from the key — they govern spend across whatever scope you attach them to.- Open AI Gateway → Budgets.
- Click New budget.
- Pick scope =
project, target = the project your VK is in. - Set window =
month, limit =$100,on_breach = block. - Save.
402 budget_exceeded. Flip on_breach to warn if you’d rather have a X-LangWatch-Budget-Warning header instead of a hard cut-off.
See Budgets for full scoping details.
Next steps
- Concepts — how VKs, budgets, guardrails, and fallback fit together.
- Fallback chains — survive provider outages with no code change.
- Caching passthrough — the load-bearing rule for keeping your 90% Anthropic cache discount.
- CLI Integrations — ship the gateway to every developer’s Claude Code / Codex / Cursor.