Education

Fixing "Provider Returned Error" on OpenRouter

"Provider returned error" is a wrapper, not a diagnosis. Here's how to tell rate limits, provider outages and malformed requests apart, fix each one fast, and stop chasing it across more than 120 providers.

BSBrittany Seales· Marketing5 min read
Fixing OpenRouter Error - SayGm blog header graphic

Updated 10 November 2026. "Provider returned error" means the model provider behind OpenRouter rejected or failed your request, not OpenRouter itself. Check the HTTP status first: a 429 is the provider's rate limit, a 502 or 503 is the provider down or overloaded, and a 400 is a request the provider won't accept. Retry with backoff for 429s and 5xxs, add a fallback model, and fix the payload for 400s. If it keeps happening, the cause is scale: OpenRouter routes across about 460 models from more than 120 providers, and every one of them is a place this error can start.

StatusWhat it meansFirst fix
429The upstream provider's rate limit was hitWait for Retry-After, then retry with backoff; add a fallback model
502The provider is down or returned an invalid responseRetry; let OpenRouter fall back to another provider
503The provider is overloaded, or no provider meets your routing rulesRetry after a short delay; loosen provider filters
400The provider rejected the request itselfFix the payload: tool calls, context length, parameters
403A moderation flag or guardrail blocked itRead error.metadata.reasons; rephrase or switch model

Status meanings are from OpenRouter's errors and debugging docs, checked 10 November 2026.

Table of Contents

"Provider returned error" is one of the most common failures developers hit when building on OpenRouter, and one of the least informative on its own. It shows up in Cursor, Cline, SillyTavern, OpenCode and any custom agent calling a chat completion API, and it hides several unrelated root causes behind one string.

This post walks through what's happening under that message, how to tell the causes apart, and what to do about each one, including the option of routing through a gateway with a smaller, curated catalog instead of debugging blind across more than 120 providers.

What "Provider Returned Error" Actually Means

OpenRouter 400 provider returned error message example

OpenRouter sits between your application and the upstream model providers. When a request fails, OpenRouter returns a JSON error object with a code, a message and a metadata field, and the metadata is where the real story lives. "Provider returned error" means the failure happened on the provider's side, after OpenRouter forwarded your request. That's why retrying the exact same call sometimes works and sometimes doesn't: the cause is usually on someone else's infrastructure, not in your code.

OpenRouter now tags every provider error with a typed error_type, such as rate_limit_exceeded, provider_unavailable or context_length_exceeded, and passes the provider's own code through as error.metadata.provider_code when it has one. Those two fields tell you more than the message does.

OpenRouter 429: Provider Returned Error

A 429 wrapped in "provider returned error" means the provider behind the model throttled the request, not OpenRouter. It's most common on free and heavily discounted routes at peak times, and it's the single biggest source of this error.

The fix is to wait and retry. OpenRouter sends a Retry-After header on 429 responses, and the OpenAI, Anthropic and Vercel AI SDKs already respect it. If your client doesn't, read the header and back off for that many seconds. If the same model keeps hitting 429s, add a fallback model, or switch to a paid route with more headroom.

A 429 that is not wrapped in "provider returned error" is different: that's OpenRouter's own limit, often from a :free model's daily cap or an empty credit balance.

OpenRouter 502 and 503: Provider Outages

A 502 means the model's provider is down or returned an invalid or empty response. A 503 means the provider is overloaded, or that no provider meets the routing rules you set. Both are almost always transient and clear within minutes, but they surface as hard failures if your code doesn't retry.

For 502s, OpenRouter may retry with another provider automatically if provider fallbacks are on, which they are by default (allow_fallbacks: true). If you've pinned a single provider, or set allow_fallbacks to false, a 502 comes straight back to you. For 503s, check whether your provider filters (data policy, quantisation, price caps) have left nothing to route to.

Errors like "model call failed: upstream returned 502", "provider turn failed" or "the AI provider returned an unexpected response" in agent tools are usually this case, reported in the tool's own words.

OpenRouter 400: Malformed Requests

A 400 means the provider rejected the request itself, and retrying the identical call will fail every time. OpenRouter's own checks are looser than each provider's, so a request can pass OpenRouter and still fail at the model.

The most common causes:

  • Broken tool calls in agent loops. A tool_use without its matching tool_result, often after a dropped or truncated turn, is the most frequent trigger.
  • Context length. The prompt plus max_tokens is over the model's window (context_length_exceeded).
  • Unsupported parameters. A parameter the chosen provider doesn't accept, such as a sampling setting or response format.

Content Moderation Blocks (403)

Some providers run their own content filters, separately from the model, so a prompt can pass OpenRouter and still be blocked downstream. OpenRouter returns these as a 403 with error.metadata.reasons, the flagged text and the provider_name that flagged it. Rephrase the prompt, or route that request to a model with different filtering.

How to Diagnose the Real Cause

Three checks separate the causes fast:

  1. Read the HTTP status alongside the message. 429 is a rate limit, 502 or 503 is an outage, 400 is a malformed request, 403 is a block.
  2. Read error.metadata. error_type names the cause, provider_code carries the provider's own code, and for moderation errors provider_name tells you who flagged it. Add the X-OpenRouter-Metadata header to see which provider was selected and which fallbacks were tried.
  3. Check whether it's reproducible. A failure that succeeds on retry is transient: a rate limit or outage. A failure that repeats identically is almost always a malformed request or a model limitation.

How to Fix It in Code

  • For 429s and outages: retry with exponential backoff, respect Retry-After, and give OpenRouter a list of fallback models with the models parameter. If the first model errors, OpenRouter tries the next in order.
  • For malformed requests: validate tool call and message structure before sending, especially in multi-turn agent loops, and keep prompts inside the context window.
  • For moderation blocks: rephrase, or route that request to a different model.
  • If it persists across retries and providers: check OpenRouter's status page before assuming the problem is yours.

With the OpenAI SDK pointed at OpenRouter, a fallback list and retries look like this:

python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://openrouter.ai/api/v1",
    api_key=os.environ["OPENROUTER_API_KEY"],
    max_retries=4,  # retries 429 and 5xx with backoff, respecting Retry-After
)

response = client.chat.completions.create(
    model="anthropic/claude-sonnet-5.5",
    messages=[{"role": "user", "content": "Summarise this changelog."}],
    extra_body={
        "models": ["anthropic/claude-sonnet-5.5", "openai/gpt-6.1-sol"],  # fallback order
        "provider": {"allow_fallbacks": True},
    },
)
print(response.choices[0].message.content)

Check your tooling rather than assuming it retries: OpenClaw shipped without this error in its retryable patterns, so the agent stopped instead of failing over (since fixed).

Provider Returned Error in Cline, SillyTavern, OpenCode and Cursor

The fix is the same in every tool; only where you change it differs.

  • Cline: "provider returned error" in Cline is almost always a 429 on a free or busy model. Switch to a paid model, or a different provider for the same model, in the API provider settings, and retry the task. Repeated 400s in long tasks usually mean a broken tool-call history; start a fresh task.
  • SillyTavern: check the console for the status code. 429s mean slow down or switch model; 403s mean the provider's content filter blocked the prompt, so switch to a model with different filtering.
  • OpenCode and Cursor: both pass OpenRouter's error through. Retry once; if it repeats, change the model, or check that your context hasn't outgrown the model's window.

If you're changing models every few days to dodge this error, that's the signal the problem is the routing layer, not your tool.

Why This Error Happens Less on SayGM

Part of what makes this error hard to get rid of on OpenRouter is scale. Routing across about 460 models from more than 120 providers means 120-plus sets of rate limits, moderation systems and outage patterns, and every one of them is a place "provider returned error" can start. None of them are things OpenRouter controls.

SayGM model leaderboard showing GPQA Diamond and MATH-500 scores with live pricing

SayGM takes a narrower approach on purpose:

SayGMOpenRouter
Catalog65 curated models from 12 upstream providers, including Claude, GPT, Gemini, DeepSeek, GLM, Kimi and QwenAbout 460 models from 121 providers
When an upstream failsThe gateway retries upstream 429 and 5xx responses on another route automatically; you only get a 429 when every matching route is rate-limitedProvider fallback to another host of the same model; model fallback only if you list models
PrivacyGateway runs inside a hardware-attested enclave; 14 models on fully sealed confidential routesPolicy and settings
Fee on buying creditNone5.5% on Standard
Switching costSame OpenAI-compatible base URL, drop-in replacement-

SayGM figures are from its live catalog at api.saygm.com/v1/models and its errors and retries docs; OpenRouter's from its models API, providers API and pricing page, all checked 10 November 2026.

It's the same kind of gateway, an OpenAI-compatible base URL you drop into existing code, but the retry this post spends most of its length on is built in: SayGM retries upstream 429 and 5xx responses on another route before the error ever reaches you, across a smaller catalog, with no fee on top. The integrations guide covers Cursor, Cline and Claude Code, and the SayGM vs OpenRouter page compares costs on your own volumes.

What Changed Since August

This post first went up on 20 August 2026. Here's what has moved since.

  • OpenRouter now tags provider errors with a typed error_type and surfaces the provider's own code as error.metadata.provider_code, so the cause is easier to read than before.
  • OpenRouter sends a Retry-After header on 429 and 503 responses.
  • OpenRouter's provider count grew to more than 120 providers, serving about 460 models (checked 10 November 2026 via its API).
  • SayGM's catalog grew from about 30 models to 65 from 12 upstream providers, 14 of them on sealed confidential routes.

FAQ

What does "provider returned error" mean on OpenRouter?

It means the model provider behind OpenRouter rejected or failed your request, not OpenRouter itself. The HTTP status tells you why: 429 is a rate limit, 502 or 503 is an outage, 400 is a request the provider won't accept, and 403 is a moderation or guardrail block.

How do I fix OpenRouter error 429?

Wait for the time in the Retry-After header, then retry with exponential backoff. If the same model keeps returning 429s, add a fallback model with the models parameter or move to a paid route with more headroom. A 429 inside "provider returned error" is the provider's limit, not OpenRouter's.

Does OpenRouter retry failed requests automatically?

Partly. Provider fallbacks are on by default, so a 502 from one provider can be retried on another provider of the same model. Falling back to a different model only happens if you list models in the models parameter. Anything else comes back to your application to retry.

Is "provider returned error" the same as a 429 rate limit?

Not necessarily. A plain 429 from OpenRouter means you've hit OpenRouter's own limit. A 429 wrapped in "provider returned error" means the upstream provider's limit was hit, which is a different fix: switch model or provider, or reduce load on that provider, rather than changing your OpenRouter plan.

Why does the same request fail sometimes and succeed other times?

That pattern is the clearest sign of a transient cause, an upstream rate limit or a brief outage, rather than something wrong with the request itself.

Final Thoughts

"Provider returned error" is a generic wrapper, not a diagnosis. Read the status code and error.metadata first, separate transient causes from structural ones, and build retry and fallback logic for the transient half, since that's most of what you'll hit.

If you're tired of working out which of 120-plus upstream providers is having a bad day, get an API key for SayGM and use a smaller, curated catalog instead: the same drop-in OpenAI-compatible setup, no credit fee, and fewer unknowns to chase.

About SayGM

SayGM is a drop-in inference gateway for teams who don't want to just take a company's word that their prompts are private. Route to a confidential model and your prompt is sealed inside hardware-verified execution, where not even SayGM can see it. That's not a policy, it's provable. Swap in your existing OpenAI, Anthropic, or Gemini code and you're covered in minutes, at transparent, published rates with no hidden markup.

Say gm to AI at saygm.com.

Website | Twitter | Discord | Blog | Medium | Docs

  • Inference
  • OpenRouter
BS

Brittany SealesMarketing

Saying gm to marketing (and AI)

X ↗