Skip to main content
The LLM Gateway lets you call models across configured providers through one standard endpoint with one LangSmith API key. This quickstart uses the OpenAI Chat Completions format to call an Anthropic model.
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:invoke and workspaces:read permissions. Ask your organization admin if you are unsure.
You can call a Gateway Credits model without a provider secret. The example below uses a bring-your-own-key Anthropic model.

1. Set environment variables

Set the standard gateway base URL and your LangSmith API key:
The unified base URL accepts provider-prefixed bring-your-own-key model IDs, such as 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.
To preserve a provider’s native API without format translation, use a direct provider route instead.

Using LangChain and Deep Agents

LangChain chat models and Deep Agents (including Deep Agents Code) support the gateway through two convenience environment variables:
This routes all supported chat models through the gateway at 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.
You can also configure base URLs and API keys for individual providers. See the following accordion for provider support and interactions with provider-specific environment variables.
  • Supported in Python only.
  • Supported chat models:
  • 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_BASE sends OpenAI to that URL while every other provider continues to use the gateway:
The following table shows how the base URL and key are resolved, using OpenAI as the example (other providers use their own *_API_BASE and *_API_KEY variables). GW default is https://gateway.smith.langchain.com/openai/v1.

2. Make a call

A 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 named gateway 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 a 402 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:
  1. Authenticates the request using the LangSmith API key.
  2. Selects a hosted model or configured bring-your-own-key provider from the model ID.
  3. Resolves the upstream credential. Hosted models use Gateway Credits, while bring-your-own-key models use workspace Provider Secrets.
  4. Evaluates active policies, including spend limits, PII redaction, and secrets redaction.
  5. Translates the request and response when the selected provider uses a different API format.
  6. Traces the call to LangSmith, including token counts, cost, and policy events.

Next steps