The LLM Gateway is in beta.
How it works
A fallback chain has:- A primary model: the provider and model that trigger the chain when a request fails.
- One to five fallbacks: an ordered list of provider models or saved model configurations. A provider model uses the workspace’s secret for that provider, or Gateway Credits for eligible hosted models.
- Triggers: the HTTP status codes that move the request to the next model. The defaults cover common timeout, rate-limit, and server errors, such as
408,429,500, and503. They do not include424, which the gateway returns when a model has no provider key in the workspace. Add424to let the chain skip a fallback without a key. A primary model without a key returns424without trying the chain. - A first-output timeout: how long each attempt can wait before the gateway moves to the next model. It is on by default at 120 seconds, and each attempt gets a fresh timer. Streaming requests in a unified API format wait for the first output. Non-streaming requests and direct model access requests wait for response headers.
- The gateway calls the primary model selected by the request’s provider-prefixed model ID.
- If the request fails with a configured trigger status, times out, or hits a transport error, the gateway loads the matching fallback chain.
- The gateway calls each fallback in order until one succeeds, returns a status that does not trigger another fallback, or the chain is exhausted.
- The gateway returns the final response in the API format used by the client.
Create a fallback chain
To create a fallback chain:- Go to LLM Gateway, and select the Model Fallbacks tab.
- Click Create fallback chain.
- Select the Workspace where the chain applies.
- Select the primary provider and model. Requests to this provider-prefixed model ID use the chain when the primary attempt fails.
- Under Fallbacks, add one to five backup models in the order the gateway should try them. Choose a provider and model directly, select an existing model configuration, or create a custom model configuration.
- Under Configure fallback triggers (advanced), review the HTTP status codes that trigger the next fallback. To add a status code, type it in the field, and select it from the list.
- (Optional) In the same section, adjust the First output timeout per model (seconds), or turn off Time to first output to remove the timeout.
- Click Create chain.
Test a chain in the Simulator
The Simulator sends a request through a fallback chain while simulating how each model in the chain behaves, so you can check the chain’s routing and added latency before a provider fails in production. To test a chain:- Go to LLM Gateway, and select the Model Fallbacks tab.
- On the chain’s row, click Open in Simulator →.
- Under Simulate provider behaviour, choose a behavior for each model in the chain (Healthy, Timeout, Rate limit, or Outage).
- Click Run request.
- Simulated failures send no inference request. To approximate network latency, the gateway calls a provider endpoint that does not generate tokens. Simulated failures have no trace.
- A simulated failure falls back only on a trigger status. Rate limit and Outage move to the next model only while
429and503are in the chain’s triggers. Both are in the defaults. - The Simulator sends non-streaming requests only. To check a chain’s streaming behavior, send a streaming request from your code.
- Errors outside the simulation still surface. If a fallback has no provider key in the workspace, its attempt returns
424, as it would in production. If the primary has no key, the Simulator asks you to add one before it runs the chain.
Make a call
Call the standard LLM Gateway endpoint with the primary model’s provider-prefixed ID. You do not need a route-specific URL or additional request fields. This example uses the base URL and API key set in Send your first LLM Gateway request:<PRIMARY_MODEL_ID> in the API key’s workspace. If no chain matches, the gateway returns the primary model’s response without attempting a fallback.
Investigate fallback attempts
When a chain runs, the response records which models the gateway tried, each attempt’s status code, and the model that served the request:- In your traces: if your application calls the gateway through a LangChain chat model in Python (
langchain-openai>=1.6.7orlangchain-anthropic>=1.7.5) with tracing on, the model’s run has a Gateway section that lists each attempt. - In the response: other clients can read the
X-LangSmith-Gateway-Metadataresponse header. Itsattempt_detailsfield lists each attempt’s model and status code, andselected_modelnames the model that served the request.
Set fallbacks for a prompt
A prompt saved in LangSmith stores a model selection with its template, so your application can pull and run both together. A fallback chain applies to every request for its primary model in its workspace. To give one prompt fallback behavior that differs from other traffic to the same model, point the prompt at its own saved model configuration, and make that configuration the chain’s primary. The prompt calls the configuration ascustom/<name>, and the gateway applies the configuration’s chain.
To configure fallbacks for a prompt:
- In Settings > Model configurations, create a model configuration for the provider and model you want the prompt to use. Note the configuration’s name,
<config_name>, which the next two steps use. An organization-scoped configuration reads the provider key from organization secrets, so if the key is a workspace secret, create a workspace configuration. - Create a fallback chain in the same workspace. For the primary model, select your configuration from the Model configurations section at the end of the model list, rather than its underlying provider and model. The chain’s primary model is
custom/<config_name>, separate from any chain on the underlying model. - Create a prompt in the Playground. Click the current model’s name to open Model Configuration, and select LangSmith Gateway as the Provider. Type
custom/<config_name>in the Model field, and click Apply. Click Start to check that the prompt runs. Click Save, and name the prompt. - In your application, pull the prompt with its model. In Python, set
include_model=Truewhen callingclient.pull_prompt.
See also
- Add a provider key: give each model in a chain a provider key.
- Monitor LLM Gateway spend: review the cost of primary and fallback attempts by model.
- Spend policies: apply cost limits alongside fallback routing.
Connect these docs to your agent of choice via MCP for real-time answers.

