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
  • Fields
  • Strategies
  • constant_delay
  • exponential_backoff
LLM Client Strategies

retry_policy

Was this page helpful?
Edit this page
Previous

fallback

Next
Built with

A retry policy can be attached to any client<llm> and will attempt to retry requests that fail due to a network error.

BAML
1retry_policy MyPolicyName {
2 max_retries 3
3}

Usage:

BAML
1client<llm> MyClient {
2 provider anthropic
3 retry_policy MyPolicyName
4 options {
5 model "claude-sonnet-4-20250514"
6 api_key env.ANTHROPIC_API_KEY
7 }
8}

Fields

max_retries
intRequired

Number of additional retries to attempt after the initial request fails.

strategy
Strategy

The strategy to use for retrying requests. Default is constant_delay(delay_ms=200).

StrategyDocsNotes
constant_delayDocs
exponential_backoffDocs

Example:

BAML
1retry_policy MyPolicyName {
2 max_retries 3
3 strategy {
4 type constant_delay
5 delay_ms 200
6 }
7}

Strategies

constant_delay

type
constant_delayRequired

Configures to the constant delay strategy.

delay_ms
int

The delay in milliseconds to wait between retries. Default: 200

exponential_backoff

type
exponential_backoffRequired

Configures to the exponential backoff strategy.

delay_ms
int

The initial delay in milliseconds to wait between retries. Default: 200

multiplier
float

The multiplier to apply to the delay after each retry. Default: 1.5

max_delay_ms
int

The maximum delay in milliseconds to wait between retries. Default: 10000