Skip to navigation

Routing and fallbacks

For each model call Meadow builds a route: an ordered list of providers to try. It sends the request to the first one. If that provider fails in a way another provider could fix, Meadow tries the next.

Next step: send one call with provider.order and read x-meadow-attempts in the response.

curl -sS -D - -o /dev/null "$MEADOW_BASE_URL/v1/chat/completions" \
-H "Authorization: Bearer $MEADOW_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-flash-lite-preview",
"provider": {"order": ["openrouter", "google"]},
"messages": [{"role": "user", "content": "Say hello in five words."}],
"max_tokens": 32
}' | grep -i x-meadow
x-meadow-attempts: 2
x-meadow-model: gemini-3.1-flash-lite-preview
x-meadow-provider: google

This is a real fallback. Our OpenRouter account does not allow that model and answered 404, so Meadow moved on and Google served the call. The response does not say which provider failed or why. Only the count is returned.

The default route

With no routing set, Meadow tries, in this order:

  1. The model’s own provider: Anthropic for Claude, Google for Gemini, OpenAI for GPT, xAI for Grok.
  2. Cloud hosts: Azure, Bedrock, Vertex.
  3. OpenRouter.

Fireworks and DeepSeek serve pinned IDs only, such as fireworks/accounts/fireworks/models/kimi-k3 or deepseek/deepseek-flash, so they are never in a default route. It skips providers you have no provider key for and providers that do not accept the request’s format. GET /v1/models lists each model’s providers in this order.

The provider object

Send provider in the request body to change the route for one call. Meadow removes it before forwarding.

FieldTypeMeaning
orderlist of providersTry these first, in this order. Providers you did not list are still tried after them, in the default order.
onlylist of providersUse only these.
ignorelist of providersNever use these.
allow_fallbacksbooleanfalse means try the first provider in the route and stop. Default true.

order alone does not restrict the route. To restrict it, use only or ignore.

Any other field in provider gets a 400 unknown field in provider routing. A provider name Meadow does not know gets a 400 invalid model provider in routing.models.<field>, where <field> is order, only or ignore, whichever held the name. The message names the project field even when the request sent it.

With the OpenAI and Anthropic SDKs, pass provider and models through extra_body. See Use your existing tools.

With the mdw CLI. mdw is sent to you during the beta. See Clients.

mdw models call --model gemini-3.1-flash-lite-preview \
--provider-order openrouter --provider-order google \
--max-tokens 32 "Say hello in five words."
served by google (gemini-3.1-flash-lite-preview) after 2 attempt(s)
Hello, it is nice meeting.

Turn fallbacks off

curl -sS "$MEADOW_BASE_URL/v1/chat/completions" \
-H "Authorization: Bearer $MEADOW_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-flash-lite-preview",
"provider": {"order": ["openrouter", "google"], "allow_fallbacks": false},
"messages": [{"role": "user", "content": "Say hello in five words."}],
"max_tokens": 32
}'
{"error":{"message":"provider failed to serve request","type":"server_error","param":null,"code":"provider_error","attempts":[{"detail":"provider returned HTTP 404","duration_ms":55,"outcome":"unsupported","provider":"openrouter"}]},"request_id":"req_0000cdac"}

The status is 502. Google was never tried. With allow_fallbacks: false the models list is ignored too.

That sample is from the hosted beta before 2026-11-28. Since then a 404 from the one provider tried is passed through, so this call returns OpenRouter’s own 404 body with x-meadow-provider: openrouter. A timeout, a 5xx or a rejected key from that provider still returns the 502 above.

Model fallbacks

models is a list of up to three more model IDs. Meadow tries them, in order, after model has failed on every provider in its route.

curl -sS -D - "$MEADOW_BASE_URL/v1/messages" \
-H "Authorization: Bearer $MEADOW_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-flash-lite-preview",
"models": ["claude-haiku-5-5"],
"max_tokens": 32,
"messages": [{"role": "user", "content": "Say hello in five words."}]
}' | grep -i -e x-meadow -e '"model"'
x-meadow-attempts: 2
x-meadow-model: claude-haiku-5-5
x-meadow-provider: anthropic
x-meadow-provider-request-id: req_000054ba...
{"model":"claude-haiku-5-5","id":"msg_000054ba...","type":"message","role":"assistant","content":[{"type":"text","text":"Hello there, friend! How are you?"}], ...}

On /v1/messages only OpenRouter can serve a Gemini model. It rejected, so Meadow moved to the second model and Anthropic served it.

Rules for models:

  • The provider object applies to every model in the list.
  • Every ID is checked before any provider is called. One plain ID that cannot be resolved (see Models), in model or in models, fails the whole request with a 404 unknown model (error.code model_not_found). A typo in model is not rescued by the list.
  • A fourth entry gets a 400 models may contain at most 3 fallback entries.
  • It cannot be combined with previous_response_id.

Project defaults and lock

A project can hold the same four fields as defaults for every call made with its keys, and per-model overrides. Meadow builds the route in layers, and a field set in a later layer replaces the same field from an earlier one:

  1. routing.models on the project.
  2. routing.models.per_model[<model id>] on the project.
  3. provider in the request.
  4. A pinned model ID (<provider>/<model>), which sets only to that one provider.

A project with "lock": true rejects layer 3 and layer 4 with a 403. models still works on a locked project, with plain IDs. Projects shows how to set defaults and a lock, and lists the 403 messages.

One case to know: a pinned ID combined with a request only that leaves out the pinned provider leaves no provider at all, and returns a 422 no allowed provider can serve this request.

What triggers a fallback

Meadow moves to the next provider when the current one:

Provider resultoutcome in attempts
Could not be reached, or the connection brokeerror
Timed out, or answered 408timeout
Answered 429rate_limited
Answered 503 or 529no_capacity
Answered any other 5xxerror
Refused your stored key: 401, 403, or Google’s API_KEY_INVALIDrefused
Has no credit or quota: 402, or a 429 with insufficient_quotarefused
Bedrock answered 400 Operation not allowed: the AWS account may not invoke modelsrefused
Bedrock or Vertex answered 400 for an anthropic-beta flag it does not accept, and the model ID is not pinnedunsupported
Answered 404 for a plain model IDunsupported
Sent a 200 that Meadow could not use: wrong content type, invalid or oversized JSON, or an empty streamerror
Opened a 200 stream with its own error eventerror, rate_limited, no_capacity, or refused

Seen live for this page: the 404 case, on blocking and streamed calls. The rest are read from the server code and covered by its tests.

The Bedrock, Vertex and insufficient_quota rows need provider accounts in those states and were not seen live. When a call ends on insufficient_quota and nothing else serves it, you get a 502 with no retry-after, not a 429, because waiting does not help.

What does not trigger a fallback

  • The provider’s 400, 409, 413, 422, or any other 4xx not listed above. Your request is at fault, so another provider would not help. You get the provider’s response as written. That includes a rejected anthropic-beta flag when the model ID is pinned.
  • A 404 for a pinned model ID. Same handling.
  • A 404 when the route has only one provider, for example with provider.only, allow_fallbacks: false, or a key for one provider of the model. Nothing is left to fall back to, so you get the provider’s 404 as written, with x-meadow-provider. On the hosted beta since 2026-11-28; before, this was a 502. Read from the server’s code and its tests.
  • Anything after the first event of a stream has reached you. See Streaming.
  • An error Meadow raises before it calls any provider: a bad request, a key limit, a locked project.

A provider 400 comes back at once, even when another provider is next in the route:

curl -sS -i "$MEADOW_BASE_URL/v1/chat/completions" \
-H "Authorization: Bearer $MEADOW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "gemini-3.1-flash-lite-preview", "messages": [{"role": "user", "content": "hi"}], "max_tokens": 32, "temperature": 9}'
HTTP/2 400
content-type: application/json; charset=UTF-8
x-content-type-options: nosniff
x-meadow-attempts: 1
x-meadow-model: gemini-3.1-flash-lite-preview
x-meadow-provider: google
x-request-id: req_00003012
[{
"error": {
"code": 400,
"message": "temperature must be in the range [0.0, 2.0] but was 9",
"status": "INVALID_ARGUMENT"
}
}
]

A pinned ID that the provider does not know also stops there, and models is not tried:

curl -sS "$MEADOW_BASE_URL/v1/chat/completions" \
-H "Authorization: Bearer $MEADOW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "google/gemini-does-not-exist", "models": ["gemini-3.1-flash-lite-preview"], "messages": [{"role": "user", "content": "hi"}], "max_tokens": 32}'
[{
"error": {
"code": 404,
"message": "models/gemini-does-not-exist is not found for API version v1main, or is not supported for generateContent. Call ModelService.ListModels to see the list of available models and their supported methods.",
"status": "NOT_FOUND"
}
}
]

How a provider error reaches you

What happenedStatusBody
A provider rejected the request itself (the cases above)The provider’s statusThe provider’s body and content type, as written. x-meadow-provider names the provider.
Every provider in the route failed502Meadow error, error.code all_providers_failed, with attempts.
Fallbacks were off and the one provider failed502Meadow error, error.code provider_error, with attempts. If the provider’s response was a 429, the status is 429 and the code is rate_limited.
No provider you have a key for can serve the model422Meadow error, error.code no_provider_key.

Every failed route looks like this:

curl -sS "$MEADOW_BASE_URL/v1/chat/completions" \
-H "Authorization: Bearer $MEADOW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "gemini-3.1-flash-lite-preview", "provider": {"only": ["openrouter"]}, "messages": [{"role": "user", "content": "hi"}], "max_tokens": 32}'
{"error":{"message":"all providers in route failed","type":"server_error","param":null,"code":"all_providers_failed","attempts":[{"detail":"provider returned HTTP 404","duration_ms":63,"outcome":"unsupported","provider":"openrouter"}]},"request_id":"req_0000fc71"}

That sample is from the hosted beta before 2026-11-28, when a 404 from the only provider in the route still ended in this 502. Since then that call returns OpenRouter’s own 404. A route whose providers all fail in other ways, such as a timeout, a 5xx or a rejected key, returns this shape.

Each entry in attempts has provider, outcome, reason and duration_ms, and detail, started_at and finished_at when Meadow has them. detail gives the provider’s HTTP status and, when Meadow recognizes it, a short code such as (not_found_error). It never contains the provider’s message text or any key. To see the provider’s own words, pin that provider and send the call again.

A failed route is not charged against a key’s request or token limit, unless a provider received the request and gave no usable answer. See Token and request limits.

Why a call went where it went

Every route leaves its reason in three places. All of them use stable codes and never provider error text. They were added on 2026-11-24 and are on the hosted beta since 2026-11-27.

  • A model call that was served carries x-meadow-route. direct: xai means the first provider in the route answered. fallback: openai quota_exceeded -> openrouter means OpenAI’s account was out of quota and OpenRouter answered.

  • A Meadow error body, and every sandbox, has attempts: one entry per provider tried, in order, with provider, outcome, reason, started_at, finished_at and duration_ms. So a sandbox that went to Modal because Daytona was full reads:

    {
    "attempts": [
    {"provider": "daytona", "outcome": "no_capacity", "reason": "quota_exceeded", "duration_ms": 412},
    {"provider": "modal", "outcome": "served", "reason": "served", "duration_ms": 3180}
    ]
    }

    That example is written from the server’s tests, not captured on the beta, and the times are left out.

  • reason is the code to branch on or count: served, no_capacity, quota_exceeded, rate_limited, timeout, auth_failed, invalid_request, refused, unsupported, no_provider_key, image_pull_failed, build_failed, provider_lost, vendor_error. New codes can be added, so treat one you do not know like vendor_error.

A route pinned to one provider shows one attempt and no fallback.

Attempts headers

x-meadow-attempts counts the providers tried, including the one that answered. 1 means no fallback happened. It is not sent on Meadow errors: count error.attempts there. Two more headers name providers that rejected your stored key or that may bill for an unused answer. Models lists every header.

Those two were not seen live for this page. Storing a provider key checks it with the provider first, so we had no rejected key to test with.

How long a route can take

Each attempt has its own time limit, so a route with three providers can take three times as long as one. Streaming lists the limits. To bound the wait, shorten the route with only, or stream.

API reference

Operations on this page: createChatCompletion, createResponse, createMessage, updateProject.