Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Environment:Openai Openai agents python LiteLLM Dependencies

From Leeroopedia
Knowledge Sources
Domains Infrastructure, Models
Last Updated 2026-02-11 14:00 GMT

Overview

Optional dependency for using 100+ non-OpenAI LLM providers via the LiteLLM routing library.

Description

The `LitellmModel` extension allows the Agents SDK to route model calls through LiteLLM, which supports Anthropic, Google, Mistral, Azure, and many other providers. The `litellm` package must be installed separately via the `[litellm]` optional dependency group. An environment variable controls an optional serializer warning patch.

Usage

Use this environment when you want to run agents with non-OpenAI models (e.g., Claude, Gemini, Mistral) via the LiteLLM routing layer.

System Requirements

Category Requirement Notes
Python >= 3.9 Same as core SDK
Network Internet access Required for LLM API calls to various providers

Dependencies

Python Packages

  • `litellm` >= 1.81.0, < 2

Credentials

  • Provider-specific API keys depending on the model used (e.g., `ANTHROPIC_API_KEY`, `GOOGLE_API_KEY`, etc.)
  • `OPENAI_AGENTS_ENABLE_LITELLM_SERIALIZER_PATCH`: Set to `"true"` to suppress LiteLLM serializer warnings

Quick Install

pip install 'openai-agents[litellm]'

Code Evidence

Import guard from `extensions/models/litellm_model.py:14-20`:

try:
    import litellm
except ImportError as _e:
    raise ImportError(
        "`litellm` is required to use the LitellmModel. You can install it via the optional "
        "dependency group: `pip install 'openai-agents[litellm]'`."
    ) from _e

Serializer patch control from `extensions/models/litellm_model.py:111-112`:

# Set OPENAI_AGENTS_ENABLE_LITELLM_SERIALIZER_PATCH=true to opt in.
_enable_litellm_patch = os.getenv("OPENAI_AGENTS_ENABLE_LITELLM_SERIALIZER_PATCH", "")

Common Errors

Error Message Cause Solution
`ImportError: litellm is required to use the LitellmModel` LiteLLM not installed `pip install 'openai-agents[litellm]'`
`No usage information returned from Litellm` Provider did not return token usage Non-fatal warning; some providers omit usage stats

Compatibility Notes

  • Model name format: LiteLLM uses provider-prefixed model names (e.g., `anthropic/claude-3-opus-20240229`).
  • Feature parity: Not all LLM providers support all OpenAI features (e.g., structured output, tool calling). Check LiteLLM docs for provider-specific capabilities.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment