> 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="/providers.md">Providers</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="/quickstart.md">Quickstart</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="/api-reference/any-llm.md">AnyLLM</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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
