> ## Documentation Index
> Fetch the complete documentation index at: https://docs.braintrust.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Context length error caused by wrong AI provider routing

> [!NOTE]
>
> **Applies to:**
>
> * Plan - Any
> * Deployment - Any
> *
> * Use case - Debugging unexpected context length errors when using a model that should support a larger context window, caused by Braintrust routing to a different AI provider

## Summary

**Issue:** Requests to a model with a large context window return a `context_length_exceeded` error with a smaller token limit than expected.

**Cause:** Multiple providers can be eligible to serve the same model name. If those providers map the name to different underlying deployments, a request may reach a deployment with a smaller context limit.

**Resolution:** Correct the model mappings or remove the affected model from providers that cannot serve it with the required limits. For Gateway requests, you can also [specify a particular eligible provider](https://docs.braintrust.dev/admin/ai-providers.md#specify-a-particular-provider).

## Resolution steps

### Step 1: Confirm which provider handled the request

Open the failed run's trace in Braintrust and check:

* The purple chat completion span (not the root span)
* `metadata.model` — confirms which model ID was sent to the provider

If the model ID matches what you expected but the error shows a smaller context limit, the request may have been routed to a provider with a different underlying deployment.

### Step 2: Fix provider configuration

Go to **Settings > Models** and do one of the following:

**Option A — Fix the primary provider:** Update the configuration for your providers to match actual limits.

**Option B — Remove, disable, or restrict additional providers:** Remove or disable providers that don't have the correct model deployed, or that map to older or smaller versions of the model. To keep a provider available for other models, use [model restrictions](https://docs.braintrust.dev/admin/ai-providers.md#restrict-available-models) to exclude the affected model. If the mapping is a custom model, remove that custom model entry.

**Option C — Check custom model mappings:** If using custom endpoints or Azure deployments, verify that the deployment name actually corresponds to the model you expect.

> **Note:** Multiple providers may serve the same model name even when their underlying deployments differ. Make sure each [eligible provider](https://docs.braintrust.dev/admin/ai-providers.md#request-routing) maps that name to the model you expect.

### Step 3: Verify the fix

Re-run your prompt with cache disabled to confirm requests now route to the correct provider and the context length error is resolved.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.