Skip to main content
LLM Config lets you set the model, API endpoint, and fallback chain so your agent always has a working model.
The user sends a prompt; the agent tries the primary model and transparently falls back if the provider fails.

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

A provider/model value in OPENAI_MODEL_NAME now routes through litellm, matching Agent(llm="provider/model").
As of PR #4795, 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

Self-hosted model via Ollama:

Pattern 3 — Multi-provider fallback for business continuity

Pattern 4 — Passing LLMConfig to a team or flow

Containers keep only .model from the LLMConfig.
base_url, api_key, and fallback_models are dropped at the container level — pin those on individual Agent(s) that need them.

Best Practices

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.
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.
Prefix models with the provider name (anthropic/, openai/, ollama/) to avoid ambiguity when using multiple providers in a fallback chain.
Deliberately trigger a failure (e.g., invalid primary model name) and verify your fallback fires correctly before going to production.
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.

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