llm parameter — PraisonAI routes to OpenAI, Anthropic, Gemini, Groq, Cohere, or a local Ollama model.
Code
Set model by 3 ways
1. OpenAI Compatible Endpoints
By Default it uses OPENAI_BASE_URL https://api.openai.com/v1
2. Litellm Compatible model names (eg: gemini/gemini-1.5-flash-8b)
3. Litellm Compatible Configuration
Advanced Configuration (Litellm Support)
This uses Litellm
1
Install Package
Install required packages:
2
Setup Environment
3
Create Agent
Create
app.py:Ollama Integration
Ollama Integration
Groq Integration
Groq Integration
Google Gemini
Google Gemini
Jan AI Integration
Jan AI Integration
LM Studio Integration
LM Studio Integration
OpenRouter Integration
OpenRouter Integration
Provider Auto-Detection (no-config first run)
When you runpraisonai run without setting --model or a model: key in config.yaml, PraisonAI inspects which supported provider credential is present in your environment and picks a provider-appropriate default — so a user whose only key is ANTHROPIC_API_KEY no longer gets an OpenAI auth error on first run.
Detection is catalogue-driven: any provider in PROVIDER_ENV_CATALOGUE (praisonaiagents/llm/catalogue.py) with its API-key env var set is recognised — not just the historical handful. The ordered preference is preserved (OpenAI still wins when multiple keys are set), and the terminal fallback is still gpt-4o-mini.
Precedence: the first catalogued credential that is set wins, in the order above (the head of the catalogue preserves the historical preference). If multiple provider keys are set, the one listed first takes effect.
Setting
llm="local" on an Agent bypasses this credential catalogue entirely and runs the Local Model Resolver — it discovers a running local server, picks the best model, and configures itself with no key. That is the explicit, user-driven local path; the keyless fallback below is the implicit one.The same resolver drives implicit defaults for
praisonai run, praisonai chat, praisonai code, praisonai init scaffolding, praisonai setup, and the bare-praisonai TUI launch — not just run. praisonai code now flows through the same resolver and first-run gate.Same resolver from the Python SDK
ConstructingAgent(instructions="…") without llm= uses the same _PROVIDER_DEFAULT_MODELS table — with OLLAMA_HOST set alone, the Agent picks ollama/llama3.2 and routes it through litellm.
ValueError: OPENAI_API_KEY environment variable is required. This is fixed as of #4795 — the SDK Agent() constructor now matches praisonai run. See Agent Model Resolution for the full flow.
Keyless local-first fallback (no env vars set)
If no cloud provider key is set and a local OpenAI-compatible endpoint answers onhttp://127.0.0.1:11434 (or wherever OPENAI_BASE_URL / OLLAMA_HOST points), PraisonAI uses that local server as the zero-config default — the first praisonai run "..." just works before you configure anything.
--model <name>on the command line.- Any cloud provider key from the table above.
- A reachable local endpoint at
OPENAI_BASE_URL→OLLAMA_HOST→http://127.0.0.1:11434. gpt-4o-minifallback.
Detection is timeout-bounded (~150 ms) and cached briefly, so the first-run hot path stays fast when nothing is listening. Cloud keys always win — the local probe is skipped entirely when any cloud key is set.
See Local Models for the full guide.
This keyless fallback is the implicit local path. To request a local model explicitly — with full engine discovery and a loud failure when a named server is missing — set
llm="local" on the Agent. See the Local Model Resolver.A local
base_url no longer captures hosted model names — gpt-*, claude*, and gemini-* keep their native adapter even behind http://localhost:11434/v1. See Mixing local and hosted models.No cloud key at all? If Ollama (or any OpenAI-compatible local server) is running, PraisonAI will use it — no API key and no config. See Keyless Local-First Run.
Routed model provider detection
When a model id routes through Bedrock, Vertex AI, or OpenRouter to reach Claude or Gemini, PraisonAI detects the true provider from the model id — not the routing prefix — so the correct streaming adapter is used.
Async streaming (
agent.astart(...)) and agent.astream(...) now work correctly for these routed model ids. Older versions fell through to the OpenAI streaming adapter and raised a runtime error on the async path.
Detection first checks known provider prefixes, then falls back to substring matching:
"claude" or "anthropic" in the model id resolves to Anthropic, and "gemini" resolves to Gemini. Genuinely-OpenAI ids (gpt-4o, openai/...) are unaffected.Primary vs Auxiliary Model
PraisonAI splits your model choice into two knobs:
The auxiliary knob falls back to
model when unset, so single-provider (Anthropic, Ollama, on-prem) setups make zero unexpected third-party calls — the auxiliary calls all stay on your configured provider.
Two config surfaces resolve the auxiliary model:
- Config-file resolver (
[defaults].small_model) — used by session-title generation viaget_small_model(primary_model, fallback). - Env-var resolver (
PRAISONAI_AUXILIARY_MODEL→OPENAI_MODEL_NAME→gpt-4o-mini) — used by memory quality scoring, context compaction, workflow routing,litehelpers, task callbacks, and learn-manager extraction. Session-title generation also falls through to this ladder whendefaults.small_modelis unset.
memory/memory.py, memory/learn/manager.py, context/compressor.py, context/optimizer.py, workflows/workflows.py, lite/__init__.py, task/task.py, and session/title.py. Cost tables (utils/cost_utils.py, llm/_cost.py), docstring examples, and public dataclass field defaults are deliberately not routed — PRAISONAI_AUXILIARY_MODEL does not change pricing behaviour. Empty or whitespace-only env values (OPENAI_MODEL_NAME=" ") are ignored.
Supported Models for No Code
Example agents.yaml
This uses Multi-Agents with Multi-LLMs.How It Works
The Agent passes yourllm value to the provider resolver, which routes the request to the matching model and returns the response.
Best Practices
Let auto-detection pick the default
Let auto-detection pick the default
Skip
llm= on first runs. PraisonAI resolves a sensible default from whichever provider key is set — see Provider Auto-Detection.Use LiteLLM prefixes for non-OpenAI providers
Use LiteLLM prefixes for non-OpenAI providers
Pass
llm="gemini/gemini-1.5-flash-8b" or llm="anthropic/claude-3-5-sonnet-latest" to target a specific provider model.Keep API keys in the environment
Keep API keys in the environment
Set provider keys in your shell or
.env. Use api_key=None in llm_config so the SDK reads the environment variable.Match model to task
Match model to task
Use a small fast model (
gpt-4o-mini, gemini-1.5-flash) for routing and a larger model only where quality matters.Related
Quick Start
Run your first agent in a few lines.
Tools
Give models real actions with tools.
Local Model Resolver
Point an Agent at any running local server with
llm="local".Keyless Local-First Run
The implicit local fallback when no cloud key is set.

