> For the complete documentation index, see [llms.txt](https://docs.mozilla.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mozilla.ai/index.md).

# Introduction

any-llm is a Python library providing a single interface to different LLM providers.

```python
from any_llm import completion

# Using the messages format
response = completion(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "What is Python?"}],
    provider="openai"
)
print(response)

# Switch providers without changing your code
response = completion(
    model="claude-sonnet-4-5-20250929",
    messages=[{"role": "user", "content": "What is Python?"}],
    provider="anthropic"
)
print(response)
```

[**Get Started**](/quickstart.md) | [**View on GitHub**](https://github.com/mozilla-ai/any-llm)

## Why any-llm

<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Switch providers in one line</strong></td><td>Change from OpenAI to Anthropic, Mistral, or any other provider with a single parameter change.</td><td><a href="/pages/Fos7cgzeThpzxpVYOw3B">/pages/Fos7cgzeThpzxpVYOw3B</a></td></tr><tr><td><strong>Unified exception handling</strong></td><td>Consistent error handling across all providers with a unified exception hierarchy.</td><td><a href="/pages/LhDNPN3ZwzRC23rSJOaM">/pages/LhDNPN3ZwzRC23rSJOaM</a></td></tr><tr><td><strong>Simple API, powerful features</strong></td><td>Streaming, tool calling, embeddings, reasoning, and more, all through one interface.</td><td><a href="/pages/4OhzogOvufejtgkZ3wVo">/pages/4OhzogOvufejtgkZ3wVo</a></td></tr></tbody></table>

## API Documentation

`any-llm` provides two main interfaces:

**Direct API Functions** (recommended for simple use cases):

* [completion](/api-reference/completion.md) - Chat completions with any provider
* [embedding](/api-reference/embedding.md) - Text embeddings
* [moderation](https://github.com/mozilla-ai/any-llm/blob/gitbook-docs/api/moderation.md) - Content moderation
* [responses](/api-reference/responses.md) - [OpenResponses](https://www.openresponses.org/) API for agentic AI systems

**AnyLLM Class** (recommended for advanced use cases):

* [Provider API](/api-reference/any-llm.md) - Lower-level provider interface with metadata access and reusability

## For AI Systems

This documentation is available in an AI-friendly format via the unified Mozilla.ai llms.txt:

* [**llms.txt**](https://docs.mozilla.ai/llms.txt) - Structured overview of all Mozilla.ai documentation for AI systems
* [**llms-full.txt**](https://docs.mozilla.ai/llms-full.txt) - Complete Mozilla.ai documentation concatenated into a single file


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.mozilla.ai/index.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
