Quick Start
1
Primary Model Only
Set just the model to get started:
2
With Fallback Chain
Add fallback models for reliability — if the primary fails, the agent automatically tries the next:
3
With LiteLLM Provider Prefix
How It Works
OPENAI_MODEL_NAME with a provider prefix
Aprovider/model value in OPENAI_MODEL_NAME now routes through litellm, matching Agent(llm="provider/model").
OPENAI_MODEL_NAME="ollama/x" (or any provider/model value) routes to litellm, matching Agent(llm="ollama/x"). Before the fix, those two paths disagreed — an OPENAI_MODEL_NAME with a provider prefix ended up on the native OpenAI client with a model name OpenAI never heard of. A bare value like OPENAI_MODEL_NAME="gpt-4o" still uses the native OpenAI client.
Configuration Options
LLMConfig SDK Reference
Full parameter reference for LLMConfig
Common Patterns
Pattern 1 — Self-hosted model via custom endpoint
Pattern 2 — Multi-provider fallback for resilience
Pattern 3 — Multi-provider fallback for business continuity
Pattern 4 — Passing LLMConfig to a team or flow
.model from the LLMConfig.
Best Practices
Always add at least one fallback model
Always add at least one fallback model
Even one fallback prevents your agent from failing completely during rate limits or outages. Use a smaller, cheaper model as the fallback — it costs less and is often available when the primary isn’t.
Use environment variables for API keys
Use environment variables for API keys
Never hardcode
api_key in your code. Leave it as None and set OPENAI_API_KEY, ANTHROPIC_API_KEY, etc. in your environment instead. LLMConfig picks them up automatically via LiteLLM.Use LiteLLM prefixes for multi-provider setups
Use LiteLLM prefixes for multi-provider setups
Prefix models with the provider name (
anthropic/, openai/, ollama/) to avoid ambiguity when using multiple providers in a fallback chain.Test your fallback chain
Test your fallback chain
Deliberately trigger a failure (e.g., invalid primary model name) and verify your fallback fires correctly before going to production.
For team-wide endpoint or fallback config, pin per-agent
For team-wide endpoint or fallback config, pin per-agent
AgentTeam(llm=LLMConfig(...)) and AgentFlow(llm=LLMConfig(...)) only propagate the .model string today. If every member should share a custom base_url / api_key / fallback_models, set an LLMConfig on each member Agent rather than on the container.Related
LLM Gateways
Route requests through a unified LLM gateway
LLM Endpoint Config
Fine-tune endpoint parameters per model
LLM Error Classification
How errors trigger fallback in the chain
Failover
Automatic failover strategies for reliability

