Beta: The LLM Gateway is in beta.
Prerequisites
Before you start, confirm that:- Your Organization admin has enabled the LLM Gateway. For bring-your-own-key models, the admin must also add the provider API key to workspace secrets. To set this up, see Admin setup.
- You have a workspace-scoped LangSmith API key attached to a role with
gateway:invokeandworkspaces:readpermissions. Ask your organization admin if you are unsure.
1. Set environment variables
Set the standard gateway base URL and your LangSmith API key:anthropic/claude-opus-5, and hosted model slugs, such as moonshotai/kimi-k3. The model ID determines the upstream route.
If your LangSmith account is on a regional instance, use the corresponding regional gateway.
Using LangChain and Deep Agents
LangChain chat models and Deep Agents (including Deep Agents Code) support the gateway through two convenience environment variables:https://gateway.smith.langchain.com. To use a different gateway (for example, the EU instance), set its URL instead of true:
If the gateway is enabled but
LANGSMITH_GATEWAY_API_KEY is unset, the gateway falls back to LANGSMITH_API_KEY.More details
More details
- Supported in Python only.
-
Supported chat models:
- Anthropic (
langchain-anthropic >= 1.5.1) - Baseten (
langchain-baseten >= 0.2.3) - Fireworks (
langchain-fireworks >= 1.5.1) - Google Gemini (
langchain-google-genai >= 4.3.2) - OpenAI (
langchain-openai >= 1.4.1).
- Anthropic (
-
Provider-specific base URLs take precedence over the gateway, so you can still route an individual provider elsewhere. For example, with the gateway enabled,
OPENAI_API_BASEsends OpenAI to that URL while every other provider continues to use the gateway:
*_API_BASE and *_API_KEY variables). GW default is https://gateway.smith.langchain.com/openai/v1.2. Make a call
200 response with a chat completion confirms that the gateway, your API key, role permissions, and selected model route are working.
3. View your trace
Open the LangSmith UI and navigate to the tracing project namedgateway or gateway-<short_api_key>-<api_key_id> in the workspace associated with your API key. You should see a new trace for the call you just made.
If your application also emits its own LangSmith traces, for example, through LangChain or LangGraph tracing, the gateway-side trace and your application trace appear as separate runs. Linking gateway traces to the parent application run is not yet supported.
4. Set a spend policy (optional)
Go to Settings → Gateway → LLM Gateway in LangSmith to create a spend policy. For example, you can set a daily $10 cap on your API key. When the cap is reached, the gateway returns a402 response with the message: "Request blocked by gateway policies: R&D Spend Cap".
See Spend policies for the full guide on policy dimensions, time windows, and conflict resolution.
How the gateway handles requests
The gateway performs these steps for each standard endpoint request:- Authenticates the request using the LangSmith API key.
- Selects a hosted model or configured bring-your-own-key provider from the model ID.
- Resolves the upstream credential. Hosted models use Gateway Credits, while bring-your-own-key models use workspace Provider Secrets.
- Evaluates active policies, including spend limits, PII redaction, and secrets redaction.
- Translates the request and response when the selected provider uses a different API format.
- Traces the call to LangSmith, including token counts, cost, and policy events.
Next steps
- Set up coding agents: route Claude Code, Codex, Gemini CLI, or Deep Agents Code through the gateway.
- API formats: use Chat Completions, Messages, or Responses through the standard endpoint.
- Direct model access: use provider-native request and response formats.
- Spend policies: configure cost limits across your organization.
- Data protection: prevent sensitive data from reaching providers.
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

