For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Help on Discord
HomeGuideExamplesBAML ReferencePlaygroundAgents.mdChangelog
HomeGuideExamplesBAML ReferencePlaygroundAgents.mdChangelog
    • Overview
  • baml-cli
    • init
    • generate
    • test
    • serve
    • dev
    • fmt
  • Language Reference
    • Types
    • function
    • test
    • template_string
    • client<llm>
    • class
    • enum
    • generator
  • Generated baml_client
    • with_options(..)
    • AbortSignal / Cancellation
    • Collector
    • logging / env vars
    • AsyncClient / SyncClient
    • TypeBuilder
    • ClientRegistry
    • client Option
    • OnTick
    • Multimodal
    • Image
    • Audio
    • Pdf
    • Video
  • Attributes
    • What are attributes?
    • @alias / @@alias
    • @description / @@description
    • @skip
    • @assert
    • @check
    • Jinja in Attributes
    • @@dynamic
  • LLM Client Providers
    • Overview
    • AWS Bedrock
    • Anthropic
    • Google AI: Gemini
    • Google: Vertex
    • OpenAI
    • OpenAI Responses API
    • OpenAI from Azure
    • OpenRouter
    • openai-generic
    • Microsoft Foundry (openai-generic)
    • Cerebras (openai-generic)
    • Groq (openai-generic)
    • Hugging Face (openai-generic)
    • Keywords AI (openai-generic)
    • Llama API (openai-generic)
    • Litellm (openai-generic)
    • LM Studio (openai-generic)
    • Ollama (openai-generic)
    • Vercel AI Gateway (openai-generic)
    • Tinfoil (openai-generic)
    • TogetherAI (openai-generic)
    • Unify AI (openai-generic)
    • vLLM (openai-generic)
  • LLM Client Strategies
    • Timeout Configuration
    • Retry Policy
    • Fallback
    • Round Robin
  • Prompt Syntax
    • What is jinja?
    • Jinja Filters
    • ctx.output_format
    • ctx.client
    • _.role
    • Variables
    • Conditionals
    • Loops
  • Editor Extension Settings
    • baml.cliPath
    • baml.generateCodeOnSave
    • baml.enablePlaygroundProxy
    • baml.syncExtensionToGeneratorVersion
Help on Discord
LogoLogo
On this page
  • Options
  • retry_policy
  • Nesting multiple fallbacks
LLM Client Strategies

fallback

Was this page helpful?
Edit this page
Previous

round-robin

Next
Built with

You can use the fallback provider to add more resilience to your application.

A fallback will attempt to use the first client, and if it fails, it will try the second client, and so on.

You can nest fallbacks inside of other fallbacks.
BAML
1client<llm> SuperDuperClient {
2 provider fallback
3 options {
4 strategy [
5 ClientA
6 ClientB
7 ClientC
8 ]
9 }
10}

Options

strategy
List[string]Required

The list of client names to try in order. Cannot be empty.

retry_policy

Like any other client, you can specify a retry policy for the fallback client. See retry_policy for more information.

The retry policy will test the fallback itself, after the entire strategy has failed.

BAML
1client<llm> SuperDuperClient {
2 provider fallback
3 retry_policy MyRetryPolicy
4 options {
5 strategy [
6 ClientA
7 ClientB
8 ClientC
9 ]
10 }
11}

Nesting multiple fallbacks

You can nest multiple fallbacks inside of each other. The fallbacks will just chain as you would expect.

BAML
1client<llm> SuperDuperClient {
2 provider fallback
3 options {
4 strategy [
5 ClientA
6 ClientB
7 ClientC
8 ]
9 }
10}
11
12client<llm> MegaClient {
13 provider fallback
14 options {
15 strategy [
16 SuperDuperClient
17 ClientD
18 ]
19 }
20}