# any-llm
[](https://blog.mozilla.ai/introducing-any-llm-a-unified-api-to-access-any-llm-provider/)
[](https://github.com/mozilla-ai/any-llm/actions/workflows/docs.yaml/)
[](https://github.com/mozilla-ai/any-llm/actions/workflows/lint.yaml/)
[](https://github.com/mozilla-ai/any-llm/actions/workflows/tests-unit.yaml/)
[](https://github.com/mozilla-ai/any-llm/actions/workflows/tests-integration.yaml/)

[](https://pypi.org/project/any-llm-sdk/)
**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](https://docs.mozilla.ai/any-llm/) | [otari.ai](https://otari.ai/) | [Try the Demos](#-try-it) | [Contributing](#-contributing)
## Quickstart
```python
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:
>
> ```bash
> pip install 'any-llm-sdk[openai,anthropic]' # or [all] for everything
> ```
> ```python
> # 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](https://docs.mozilla.ai/any-llm/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:
```bash
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](https://docs.mozilla.ai/any-llm/providers/) to choose which ones you need.
Using an OpenAI-compatible gateway or local server that isn't listed? You don't need a dedicated provider entry: see [Custom OpenAI-compatible Endpoints](https://docs.mozilla.ai/any-llm/quickstart#custom-openai-compatible-endpoints).
### Setting Up API Keys
Set environment variables for your chosen providers:
```bash
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](#usage) examples).
## Otari Gateway
For budget management, API key management, usage analytics, and multi-tenant support, see [mozilla-ai/otari](https://github.com/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](https://github.com/mozilla-ai/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:
```python
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:
```python
response = completion(
model="mistral:mistral-small-latest", #