Prompt

How do I set fallback rules for LLM requests when a provider fails?

Artificial Intelligence / AI Infrastructure2 observationsLast seen Nov 2, 2026

Latest observation

Nov 2, 2026OpenAI APIWeb search: off

A good way to set fallback rules is to define a routing policy that decides:

  1. When to retry
  2. When to switch providers/models
  3. How many attempts are allowed
  4. What counts as a failure
  5. Whether to fail open or fail closed

Practical fallback strategy

1) Classify failures

Not every error should trigger a fallback.

Retry same provider/model

  • transient 5xx errors
  • rate limits
  • network timeouts
  • connection resets

Fallback to another provider/model

  • repeated 5xx errors
  • provider outage
  • quota exhausted
  • unsupported model/context size
  • persistent latency beyond threshold

Do not fallback automatically

  • authentication failures
  • invalid request schema
  • safety/policy refusals
  • bad prompt formatting

2) Use a priority chain

Define providers in order of preference:

Primary: OpenAI GPT-4.1
Secondary: Anthropic Claude
Tertiary: Google Gemini
Backup: smaller local model

Then add rules like:

  • Try primary first
  • Retry primary up to 2 times on transient errors
  • If still failing, move to secondary
  • If secondary also fails, continue down the chain
  • Stop after max attempts or return a graceful error

3) Set thresholds

Common thresholds:

  • Retries per provider: 1–3
  • Timeout per request: 10–30 seconds
  • Total time budget: 30–60 seconds
  • Circuit breaker: temporarily disable a failing provider after repeated errors
  • Cooldown window: e.g. 5 minutes before trying it again

Example logic:

  • 1st attempt: primary
  • 2nd attempt: primary retry
  • 3rd attempt: secondary
  • 4th attempt: tertiary
  • Final: return fallback response or error

4) Keep request compatibility in mind

Fallback only works if the backup model can handle the request.

Check:

  • context length
  • tool/function calling support
  • structured output compatibility
  • multimodal support
  • streaming support
  • JSON/schema adherence

If the fallback model is weaker, you may need to:

  • shorten the prompt
  • remove optional context
  • relax output format requirements
  • post-process output

5) Decide on response policy

When all providers fail, choose one:

  • return an explicit error
  • return a cached/stale answer
  • return a simplified heuristic response
  • queue for later processing
  • notify the user and ask to retry

Example fallback policy

providers:
  - name: primary
    model: gpt-4.1
    retries: 2
    retry_on:
      - timeout
      - rate_limit
      - server_error
  - name: secondary
    model: claude-sonnet
    retries: 1
    retry_on:
      - timeout
      - rate_limit
      - server_error
  - name: tertiary
    model: gemini-pro
    retries: 0

global:
  request_timeout_ms: 15000
  max_total_attempts: 4
  fallback_on:
    - timeout
    - rate_limit
    - server_error
  do_not_fallback_on:
    - invalid_request
    - auth_error
    - policy_refusal

Pseudocode

providers = [primary, secondary, tertiary]

for provider in providers:
    for attempt in range(provider.retries + 1):
        try:
            return provider.call(request, timeout=15)
        except TransientError:
            if attempt == provider.retries:
                break
            continue
        except FatalError:
            raise

raise RuntimeError("All providers failed")

Best practices

  • Log the failure reason and provider used
  • Track latency and success rate per provider
  • Prefer idempotent requests if retries are enabled
  • Use exponential backoff for retries
  • Avoid retry storms during outages
  • Test fallback behavior regularly

If you want, I can also give you:

  • a Python implementation
  • a Node.js implementation
  • or a YAML config pattern for provider fallback rules

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (2 observations for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.