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

PraisonAI bounds LLM calls at two layers so an unresponsive provider cannot pin a request indefinitely. See LLM Timeouts for the full guide.

Default on direct LLM / Agent(llm=“model”) path

Agents built with praisonaiagents get a 600 second (10 minute) per-request timeout when timeout is not set.
For streaming calls the 600 s is a read-gap bound (max gap between chunks), not the total call duration.

Default on framework registry / gateway path

Calls dispatched through the praisonai provider registry (openai, anthropic, google, groq, mistral, bedrock, azure, ollama, xai, deepseek, cohere, together, sagemaker) and gateway providers (openrouter, litellm-proxy, custom-gateway) are bounded by two defaults.
A malformed value (PRAISONAI_LLM_TIMEOUT=abc) logs a warning and falls back to 60.
Behaviour change (PraisonAI PR #5972): an unset timeout on the direct LLM / Agent(llm=...) path now resolves to 600 s instead of being left to litellm’s 6000 s ceiling — a stuck provider now stops the turn after 10 minutes instead of 100. Pass timeout=None to restore the old behaviour.The registry/gateway defaults were introduced earlier in v4.6.163 (PraisonAI PR #3879). Before that, registry calls had no timeout — a black-holed provider would hold a request open until the OS TCP keepalive gave up (~2 hours on Linux defaults).

Core LLM Configuration

Basic Setup

Behaviour change (PraisonAI PR #4245). Before this release, temperature set inside Agent(llm={...}) was silently overridden by a hardcoded 1.0 at request time — configured values never reached the provider. It now reaches the request as written. If you set temperature via the llm dict, your output will change; if you did not set it, the provider default now applies (previously an explicit 1.0 was sent). Setting temperature per call still wins over the instance/config value.
Temperature precedence: per-call temperature= kwarg > Agent(llm={'temperature': ...}) / Agent(temperature=...) > provider default (temperature omitted from the request). When temperature is not configured anywhere, the parameter is omitted from the request rather than sent as an explicit None or 1.0. This matters for providers whose default differs from 1.0 — for example reasoning models that reject non-default temperatures (see the note in JS output).
To confirm the value reached the request, enable LiteLLM debug logging or check your provider dashboard for the temperature recorded on the call.

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. This covers every agent shape — provider/model strings, custom base_url servers, and model-object LLMs — on sync, async, and streaming turns.

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