any-llm-sdk 1.23.0


pip install any-llm-sdk

  Latest version

Released: Jul 29, 2026


Meta
Requires Python: >=3.11

Classifiers

Project logo

any-llm

Read the Blog Post

Docs

Linting Unit Tests Integration Tests

Python 3.11+ PyPI Discord

Communicate with any LLM provider using a single, unified interface. Switch between OpenAI, Anthropic, Azure / Microsoft Foundry, Mistral, Ollama, and more without changing your code.

Documentation | otari.ai | Try the Demos | Contributing

Quickstart

pip install 'any-llm-sdk[mistral,ollama]'

export MISTRAL_API_KEY="YOUR_KEY_HERE"  # or OPENAI_API_KEY, etc
from any_llm import completion
import os

# Make sure you have the appropriate environment variable set
assert os.environ.get('MISTRAL_API_KEY')

response = completion(
    model="mistral-small-latest",
    provider="mistral",
    messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)

That's it! Change the provider name and add provider-specific keys to switch between LLM providers.

Coming from LiteLLM? Your API keys and environment variables carry over unchanged. Install the SDK with extras for the providers you need, then update your import and model strings:

pip install 'any-llm-sdk[openai,anthropic]'  # or [all] for everything
# before
from litellm import completion
response = completion(model="openai/gpt-4o", messages=[...])

# after
from any_llm import completion
response = completion(model="openai:gpt-4o", messages=[...])

See Supported Providers to map your existing model strings.

That's the full migration — no proxy, no extra config.

Installation

Requirements

  • Python 3.11 or newer
  • API keys for whichever LLM providers you want to use

Basic Installation

Install support for specific providers:

pip install 'any-llm-sdk[openai]'           # Just OpenAI
pip install 'any-llm-sdk[mistral,ollama]'   # Multiple providers
pip install 'any-llm-sdk[all]'              # All supported providers

See our list of supported providers to choose which ones you need.

Setting Up API Keys

Set environment variables for your chosen providers:

export OPENAI_API_KEY="your-key-here"
export ANTHROPIC_API_KEY="your-key-here"
export MISTRAL_API_KEY="your-key-here"
# ... etc

Alternatively, pass API keys directly in your code (see Usage examples).

Otari Gateway

For budget management, API key management, usage analytics, and multi-tenant support, see mozilla-ai/otari.

Why choose any-llm?

  • Simple, unified interface - Single function for all providers, switch models with just a string change
  • Developer friendly - Full type hints for better IDE support and clear, actionable error messages
  • Leverages official provider SDKs - Ensures maximum compatibility
  • Stays framework-agnostic so it can be used across different projects and use cases
  • Battle-tested - Powers our own production tools (any-agent)

Usage

any-llm offers two main approaches for interacting with LLM providers:

Option 1: Direct API Functions (Recommended for Bootstrapping and Experimentation)

Recommended approach: Use separate provider and model parameters:

from any_llm import completion
import os

# Make sure you have the appropriate environment variable set
assert os.environ.get('MISTRAL_API_KEY')

response = completion(
    model="mistral-small-latest",
    provider="mistral",
    messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)

Alternative syntax: Use combined provider:model format:

response = completion(
    model="mistral:mistral-small-latest", # <provider_id>:<model_id>
    messages=[{"role": "user", "content": "Hello!"}]
)

Option 2: AnyLLM Class (Recommended for Production)

For applications that need to reuse providers, perform multiple operations, or require more control:

from any_llm import AnyLLM

llm = AnyLLM.create("mistral", api_key="your-mistral-api-key")

response = llm.completion(
    model="mistral-small-latest",
    messages=[{"role": "user", "content": "Hello!"}]
)

When to Use Which Approach

Approach Best For Connection Handling
Direct API Functions (completion) Scripts, notebooks, single requests New client per call (stateless)
AnyLLM Class (AnyLLM.create) Production apps, multiple requests Reuses client (connection pooling)

Both approaches support identical features: streaming, tools, responses API, etc.

Responses API

For providers that implement the OpenAI-style Responses API, use responses or aresponses:

from any_llm import responses

result = responses(
    model="gpt-4o-mini",
    provider="openai",
    input_data=[
        {"role": "user", "content": [
            {"type": "text", "text": "Summarize this in one sentence."}
        ]}
    ],
)

# Non-streaming returns an OpenAI-compatible Responses object alias
print(result.output_text)

Finding the Right Model

The provider_id should match our supported provider names.

The model_id is passed directly to the provider. To find available models:

  • Check the provider's documentation
  • Use our list_models API (if the provider supports it)

Motivation

The landscape of LLM provider interfaces is fragmented. While OpenAI's API has become the de facto standard, providers implement slight variations in parameter names, response formats, and feature sets. This creates a need for light wrappers that gracefully handle these differences while maintaining a consistent interface.

Existing Solutions and Their Limitations:

  • LiteLLM: Popular but reimplements provider interfaces rather than leveraging official SDKs, leading to potential compatibility issues.
  • AISuite: Clean, modular approach but lacks active maintenance, comprehensive testing, and modern Python typing standards.
  • Framework-specific solutions: Some agent frameworks either depend on LiteLLM or implement their own provider integrations, creating fragmentation
  • Proxy Only Solutions: solutions like OpenRouter and Portkey require a hosted proxy between your code and the LLM provider.

any-llm addresses these challenges by leveraging official SDKs when available, maintaining framework-agnostic design, and requiring no proxy servers.

Documentation

Contributing

We welcome contributions from developers of all skill levels! Please see our Contributing Guide or open an issue to discuss changes.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

1.23.0 Jul 29, 2026
1.22.1 Jul 22, 2026
1.22.0 Jul 22, 2026
1.21.0 Jul 16, 2026
1.20.0 Jul 14, 2026
1.19.0 Jun 26, 2026
1.18.0 Jun 22, 2026
1.17.0 Jun 05, 2026
1.16.0 Jun 03, 2026
1.15.0 May 19, 2026
1.14.0 May 01, 2026
1.13.0 Mar 23, 2026
1.12.1 Mar 18, 2026
1.11.1 Mar 18, 2026
1.11.0 Mar 12, 2026
1.10.0 Mar 05, 2026
1.9.0 Mar 03, 2026
1.8.6 Feb 25, 2026
1.8.5 Feb 16, 2026
1.8.4 Feb 16, 2026
1.8.3 Feb 13, 2026
1.8.2 Feb 11, 2026
1.8.1 Feb 11, 2026
1.8.0 Feb 04, 2026
1.7.0 Jan 16, 2026
1.6.2 Jan 13, 2026
1.6.1 Jan 12, 2026
1.6.0 Jan 06, 2026
1.5.0 Dec 23, 2025
1.4.3 Dec 18, 2025
1.4.2 Dec 16, 2025
1.4.1 Dec 15, 2025
1.4.0 Dec 04, 2025
1.3.0 Dec 01, 2025
1.2.0 Nov 06, 2025
1.1.0 Oct 29, 2025
1.0.0 Oct 22, 2025
0.21.0 Oct 14, 2025
0.20.3 Sep 20, 2025
0.20.2 Sep 11, 2025
0.20.1 Sep 09, 2025
0.20.0 Sep 09, 2025
0.19.1 Sep 08, 2025
0.19.0 Sep 08, 2025
0.18.0 Sep 05, 2025
0.17.2 Sep 02, 2025
0.17.1 Aug 26, 2025
0.17.0 Aug 26, 2025
0.16.0 Aug 22, 2025
0.15.0 Aug 21, 2025
0.14.2 Aug 20, 2025
0.14.1 Aug 20, 2025
0.14.0 Aug 19, 2025
0.13.1 Aug 15, 2025
0.13.0 Aug 15, 2025
0.12.1 Aug 14, 2025
0.12.0 Aug 14, 2025
0.11.2 Aug 13, 2025
0.11.1 Aug 13, 2025
0.11.0 Aug 12, 2025
0.10.0 Aug 11, 2025
0.9.0 Aug 08, 2025
0.8.1 Aug 08, 2025
0.8.0 Aug 07, 2025
0.7.0 Aug 06, 2025
0.6.0 Aug 05, 2025
0.5.0 Aug 05, 2025
0.4.0 Aug 04, 2025
0.3.0 Jul 31, 2025
0.2.0 Jul 24, 2025
0.1.1 Jul 18, 2025
0.1.0 Jul 18, 2025
0.0.5 Jul 17, 2025
0.0.4 Jul 16, 2025
0.0.3 Jul 16, 2025
0.0.2 Jul 15, 2025
0.0.1 Jul 15, 2025

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras:
Dependencies:
pydantic (<3,>2)
openai (>=1.99.3)
openresponses-types (>=2.3.0.post1)
anthropic (>=0.83.0)
rich
httpx
typing_extensions (>=4.5.0)