The LLM Gateway is in beta.
Prerequisites
- An admin has completed any required gateway setup.
- You have a workspace-scoped LangSmith API key. For key types, permissions, and the header each client sends, see Authenticate to the LLM Gateway.
- For bring-your-own-key models, your workspace has the corresponding provider secret. Gateway Credits models do not require a provider secret.
- Claude Code uses the standard Anthropic Messages format.
- Codex and Deep Agents Code use the standard OpenAI-compatible formats.
- Gemini CLI uses Google’s native API and requires direct model access.
Claude Code CLI
Claude Code always authenticates to the gateway with your LangSmith API key. It supports two ways for the gateway to authenticate to Anthropic, each with a different billing owner. Choose one before configuring:- Workspace provider secret: The organization manages billing and policies through a provider key stored in workspace secrets. Use this method for org-managed usage.
- Claude subscription OAuth: Anthropic bills LLM calls to the user’s personal Claude Plus or Max subscription instead of the workspace provider secret. LangSmith still enforces gateway permissions, rate limit, model access, and data policies, and traces each call. Spend limits do not apply. Use this method when developers have their own subscriptions.
Use a workspace provider secret
SetANTHROPIC_API_KEY to your LangSmith API key. Claude Code reads these variables from your shell environment or from the env block in a settings file passed with --settings.
If your LangSmith deployment is on a regional instance, replace the gateway hostname in the examples below with your regional gateway hostname. On a self-hosted installation, replace https://gateway.smith.langchain.com with https://<your-hostname>/gateway.
Use Anthropic models only
SetANTHROPIC_BASE_URL to the Anthropic-format gateway endpoint. The gateway infers the anthropic/ provider prefix from the endpoint.
- Settings file (recommended)
- Environment variables
Variables declared in a Replace
--settings file take precedence over anything already exported in your shell, so the gateway URL and API key are guaranteed to override any ambient ANTHROPIC_* values that may already be set in your environment (for example, from a global shell profile or another tool).YOUR_LANGSMITH_KEY_HERE with your LangSmith API key.Route model tiers across providers
SetANTHROPIC_BASE_URL to the gateway root, then map each Claude model tier to a provider-prefixed gateway model ID.
- Settings file (recommended)
- Environment variables
Variables declared in a Replace
--settings file take precedence over anything already exported in your shell, so gateway URLs, the API key, and model mappings are guaranteed to override any ambient ANTHROPIC_* values.YOUR_LANGSMITH_KEY_HERE with your LangSmith API key.Use Claude subscription OAuth
Claude subscription OAuth requires an active Claude Code Plus or Max subscription. If you are using a workspace Anthropic API key, use the workspace provider secret method instead.
ANTHROPIC_API_KEY in workspace provider secrets.
Log in to Claude Code with your subscription, then configure the gateway.
- Settings file (recommended)
- Environment variables
Variables declared in a Replace
--settings file take precedence over anything already exported in your shell, so the gateway URL and custom headers are guaranteed to override any ambient ANTHROPIC_* values. The settings file also keeps your LangSmith API key out of your shell history and dotfiles.YOUR_LANGSMITH_KEY_HERE with your LangSmith API key.anthropic-beta header.
The LangSmith API key authenticates the gateway request and remains subject to gateway permissions and to rate limit, model access, and data policies. The gateway forwards the OAuth bearer to Anthropic, so Anthropic bills the call to the user’s Claude subscription instead of the workspace provider secret. Spend limits do not apply to these calls, and the calls are left out of spend totals. To confirm calls route through the gateway, check that traces appear in the gateway tracing project as described in Verify the setup.
Codex CLI
Codex uses the Responses API. Add the following to~/.codex/config.toml to call the hosted Kimi K3 model with Gateway Credits through the standard endpoint:
model with its provider-prefixed ID, such as openai/gpt-5.4-mini.
Gemini CLI
Gemini CLI sends Google’s native Generate Content requests, which the standard endpoint does not expose. Follow Direct model access to configure the/gemini route, then run:
Deep Agents Code
Use the OpenAI-compatible client with the standard endpoint, then pass the hosted model slug through theopenai integration:
openai:, for example, openai:anthropic/claude-opus-5. For provider-native integrations and model IDs, see Direct model access.
Company-wide deployment
For organizations rolling the gateway out to all developers, distribute the configuration through mobile device management or a shared shell profile. Distribute:- The standard gateway base URL for each client.
- A workspace-scoped LangSmith API key per user or per cost center, depending on your policy granularity.
- The model IDs approved for each coding agent.
- The Codex
config.tomlif your organization uses Codex.
Group calls into conversation threads
The gateway maps recognized coding-agent session headers to LangSmiththread_id metadata. Calls with the same ID belong to the same conversation thread within a tracing project.
Header detection works across all providers, request paths, and API formats. The gateway checks these headers in order:
X-Claude-Code-Session-IdX-Deepseek-Harness-Session-Idthread-idthread_idsession-idsession_id
conversation field, either a string or an object’s id, and falls back to prompt_cache_key. The gateway reads these fields only when it already loads the request body for another reason, such as a guard policy. Send a header for consistent threading.
To set a thread ID explicitly, send X-Gateway-Thread-Id or set thread_id in the JSON object in X-Gateway-Metadata. A nonblank explicit value overrides automatic detection. If both metadata headers specify a thread ID, X-Gateway-Metadata takes precedence.
If the gateway finds no explicit ID, recognized session header, or body field, it does not add thread_id metadata.
Verify the setup
After configuring a coding agent, make a test call and confirm that:- The call succeeds and the agent receives a response.
- A trace appears in the
gatewaytracing project in your LangSmith workspace.
401 or 403, see Fix authentication errors. If a bring-your-own-key call fails with a 424 mentioning a missing provider key, ask a workspace admin to add the provider’s key to workspace secrets. For details, see Fix provider credential errors.
See also
- Gateway Credits: call hosted models without a provider secret.
- Direct model access: configure provider-native routes for coding agents that require them.
- Spend policies: set cost limits on developer LLM usage.
- View LLM Gateway traces: understand where gateway traces appear.
Connect these docs to your agent of choice via MCP for real-time answers.

