Skip to main content

LLM Configuration

This page provides comprehensive documentation for configuring Large Language Models (LLMs) in PraisonAI, including retry mechanisms, timeout settings, custom headers, and advanced optimization options.

Environment Variable Precedence

PraisonAI resolves LLM configuration from environment variables using a documented precedence order, ensuring consistent behavior across all components. Defaults:
  • Model: gpt-4o-mini
  • Base URL: Provider-specific or https://api.openai.com/v1
  • API Key: None
PraisonAI resolves these once at startup; all internal components use the same values. For complete environment variable configuration guide, see LLM Endpoint Configuration.

Default LLM Timeouts

Every LLM call PraisonAI dispatches through LiteLLM — for registry providers (openai, anthropic, google, groq, mistral, bedrock, azure, ollama, xai, deepseek, cohere, together, sagemaker) and gateway providers (openrouter, litellm-proxy, custom-gateway) — is bounded by two defaults so an unresponsive provider cannot pin a request coroutine or a worker thread indefinitely.
A malformed value (PRAISONAI_LLM_TIMEOUT=abc) logs a warning and falls back to 60.
Introduced in v4.6.163 (PraisonAI PR #3879). Before this release, LLM calls had no timeout — a black-holed provider would hold a request coroutine open until the OS TCP keepalive gave up (~2 hours on Linux defaults). If you were setting timeout= at every call site as a workaround, you no longer need to.

Core LLM Configuration

Basic Setup

Provider-Specific Configuration

Retry Logic Configuration

Basic Retry Settings

Advanced Retry Logic

Custom Retry Logic Implementation

Timeout Configuration

Timeout Settings

Request-Specific Timeouts

Custom Headers Configuration

Basic Headers

Dynamic Headers

Provider-Specific Headers

Advanced LLM Configuration

Load Balancing

Model Fallback Configuration

See Model Fallback for the full guide.
On transient errors (503, timeout, overloaded), the agent retries the same turn against the next model in the list. Configure fallbacks with LLMConfig(fallback_models=[...]) — not via raw config dict keys.

Request Optimization

Rate Limiting Configuration

Complete Configuration Example

Model fallback is configured via LLMConfig(fallback_models=[...]), not keys inside the llm dict above. See Model Fallback.

Environment Variables

PRAISONAI_LLM_TIMEOUT is the only PRAISONAI_LLM_* variable wired into the SDK today — see Default LLM Timeouts.

Planned (not yet wired)

The variables below are not read by the SDK yet. Exporting them has no effect. They are listed for roadmap visibility only.
For a per-call retry override today, pass num_retries= on the call — the default is 2. For per-call header, timeout, or streaming control, set them inside the llm={...} dict on the Agent (see Core LLM Configuration).

Monitoring and Debugging

See Also