Skip to main content

Client-Side Fallbacks

Set fallbacks in the .completion() call for SDK and client-side for proxy.

In this request the following will occur:

  1. The request to model="zephyr-beta" will fail
  2. litellm proxy will loop through all the model_groups specified in fallbacks=["gpt-5.6-luna"]
  3. The request to model="gpt-5.6-luna" will succeed and the client making the request will get a response from gpt-5.6-luna

👉 Key Change: "fallbacks": ["gpt-5.6-luna"]

from litellm import Router

router = Router(model_list=[...]) # defined in Step 1.

resp = router.completion(
model="gpt-5.6-luna",
messages=[{"role": "user", "content": "Hey, how's it going?"}],
mock_testing_fallbacks=True, # 👈 trigger fallbacks
fallbacks=[
{
"model": "claude-sonnet-5",
"messages": [{"role": "user", "content": "What is LiteLLM?"}],
}
],
)

print(resp)

Control Fallback Prompts​

Pass in messages/temperature/etc. per model in fallback (works for embedding/image generation/etc. as well).

Key Change:

fallbacks = [
{
"model": <model_name>,
"messages": <model-specific-messages>
... # any other model-specific parameters
}
]
from litellm import Router

router = Router(model_list=[...]) # defined in Step 1.

resp = router.completion(
model="gpt-5.6-luna",
messages=[{"role": "user", "content": "Hey, how's it going?"}],
mock_testing_fallbacks=True, # 👈 trigger fallbacks
fallbacks=[
{
"model": "claude-sonnet-5",
"messages": [{"role": "user", "content": "What is LiteLLM?"}],
}
],
)

print(resp)

To set fallbacks for every request in the gateway config instead, see Fallbacks.

LiteLLM Enterprise
SSO/SAML, audit logs, spend tracking, multi-team management, and guardrails, built for production.
Learn more →