# mozilla-ai/any-llm architecture

> Architecture diagram of the GitHub repository mozilla-ai/any-llm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mozilla-ai/any-llm
- Repository: https://github.com/mozilla-ai/any-llm

## Overview

any-llm is a Python SDK that presents a unified, typed interface to many LLM providers. A developer can call the direct API functions or create a reusable AnyLLM instance, select a provider and model, and receive normalized results; provider adapters handle provider-specific interaction. The README also documents streaming, tools, Responses API, model listing, and structured outputs. Provider dispatch and adapter relationships are supported by the README and registry documentation; detailed internals of unsampled modules are not inferred.

Main entry points: [`src/any_llm/providers/openai/base.py`](https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/providers/openai/base.py) (OpenAI adapter), [`src/any_llm/any_llm.py`](https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/any_llm.py) (AnyLLM client), [`src/any_llm/providers/anthropic/base.py`](https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/providers/anthropic/base.py) (Anthropic adapter), [`src/any_llm/api.py`](https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/api.py) (Direct API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["SDK entry points"]
  node_api["Direct API<br/>[api.py]"]
  node_anyllm["AnyLLM client<br/>[any_llm.py]"]
end

subgraph group_dispatch["Provider dispatch"]
  node_registry["Provider registry<br/>[registry.py]"]
end

subgraph group_adapters["Provider adapters"]
  node_provider_adapters["Provider adapters"]
  node_openai_adapter["OpenAI adapter<br/>[base.py]"]
  node_anthropic_adapter["Anthropic adapter<br/>[base.py]"]
end

subgraph group_core["Shared runtime"]
  node_schemas["Typed API schemas"]
  node_completion_types["Completion types<br/>[completion.py]"]
  node_message_types["Message types<br/>[messages.py]"]
  node_response_types["Responses types<br/>[responses.py]"]
  node_structured_output["Structured output"]
  node_async_runtime["Async runtime<br/>[aio.py]"]
  node_error_handling["Error handling"]
  node_exceptions["SDK exceptions<br/>[exceptions.py]"]
  node_logging["Logging<br/>[logging.py]"]
end

node_developer(("Application developer"))
node_provider_service(("LLM providers"))

node_developer -->|"calls directly"| node_api
node_developer -->|"creates client"| node_anyllm
node_anyllm -->|"resolves provider"| node_registry
node_api -.->|"selects provider"| node_provider_adapters
node_registry -->|"builds compatible class"| node_openai_adapter
node_provider_adapters -->|"sends requests"| node_provider_service
node_openai_adapter -.->|"calls SDK"| node_provider_service
node_anthropic_adapter -.->|"calls SDK"| node_provider_service
node_anyllm -->|"uses request types"| node_schemas
node_openai_adapter -->|"converts results"| node_completion_types
node_anthropic_adapter -->|"converts results"| node_message_types
node_anyllm -->|"parses output"| node_structured_output
node_openai_adapter -->|"checks format"| node_structured_output
node_anyllm -->|"bridges async calls"| node_async_runtime
node_openai_adapter -.->|"normalizes failures"| node_error_handling
node_error_handling -->|"raises SDK errors"| node_exceptions
node_openai_adapter -.->|"logs activity"| node_logging

click node_api "https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/api.py"
click node_anyllm "https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/any_llm.py"
click node_registry "https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/providers/registry.py"
click node_provider_adapters "https://github.com/mozilla-ai/any-llm/tree/main/src/any_llm/providers"
click node_openai_adapter "https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/providers/openai/base.py"
click node_anthropic_adapter "https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/providers/anthropic/base.py"
click node_schemas "https://github.com/mozilla-ai/any-llm/tree/main/src/any_llm/types"
click node_completion_types "https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/types/completion.py"
click node_message_types "https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/types/messages.py"
click node_response_types "https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/types/responses.py"
click node_structured_output "https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/utils/structured_output.py"
click node_async_runtime "https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/utils/aio.py"
click node_error_handling "https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/utils/exception_handler.py"
click node_exceptions "https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/exceptions.py"
click node_logging "https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/logging.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api,node_anyllm toneBlue
class node_registry toneAmber
class node_provider_adapters,node_openai_adapter,node_anthropic_adapter toneMint
class node_schemas,node_completion_types,node_message_types,node_response_types,node_structured_output,node_async_runtime,node_error_handling,node_exceptions,node_logging toneRose
class node_developer,node_provider_service toneIndigo
```

## Components

### SDK entry points

- [Direct API](https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/api.py): `src/any_llm/api.py`
- [AnyLLM client](https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/any_llm.py): `src/any_llm/any_llm.py`

### Provider dispatch

- [Provider registry](https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/providers/registry.py): `src/any_llm/providers/registry.py`

### Provider adapters

- [Provider adapters](https://github.com/mozilla-ai/any-llm/tree/main/src/any_llm/providers): `src/any_llm/providers`
- [OpenAI adapter](https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/providers/openai/base.py): `src/any_llm/providers/openai/base.py`
- [Anthropic adapter](https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/providers/anthropic/base.py): `src/any_llm/providers/anthropic/base.py`

### Shared runtime

- [Typed API schemas](https://github.com/mozilla-ai/any-llm/tree/main/src/any_llm/types): `src/any_llm/types`
- [Completion types](https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/types/completion.py): `src/any_llm/types/completion.py`
- [Message types](https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/types/messages.py): `src/any_llm/types/messages.py`
- [Responses types](https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/types/responses.py): `src/any_llm/types/responses.py`
- [Structured output](https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/utils/structured_output.py): `src/any_llm/utils/structured_output.py`
- [Async runtime](https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/utils/aio.py): `src/any_llm/utils/aio.py`
- [Error handling](https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/utils/exception_handler.py): `src/any_llm/utils/exception_handler.py`
- [SDK exceptions](https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/exceptions.py): `src/any_llm/exceptions.py`
- [Logging](https://github.com/mozilla-ai/any-llm/blob/main/src/any_llm/logging.py): `src/any_llm/logging.py`

### Other components

- **Application developer**
- **LLM providers**

## Connections

- Application developer → Direct API: calls directly (evidence: `README.md`)
- Application developer → AnyLLM client: creates client (evidence: `README.md`)
- AnyLLM client → Provider registry: resolves provider (evidence: `src/any_llm/providers/registry.py`)
- Direct API → Provider adapters: selects provider
- Provider registry → OpenAI adapter: builds compatible class (evidence: `src/any_llm/providers/registry.py`)
- Provider adapters → LLM providers: sends requests (evidence: `README.md`)
- OpenAI adapter → LLM providers: calls SDK
- Anthropic adapter → LLM providers: calls SDK
- AnyLLM client → Typed API schemas: uses request types (evidence: `src/any_llm/any_llm.py`)
- OpenAI adapter → Completion types: converts results (evidence: `src/any_llm/providers/openai/base.py`)
- Anthropic adapter → Message types: converts results (evidence: `src/any_llm/providers/anthropic/base.py`)
- AnyLLM client → Structured output: parses output (evidence: `src/any_llm/any_llm.py`)
- OpenAI adapter → Structured output: checks format (evidence: `src/any_llm/providers/openai/base.py`)
- AnyLLM client → Async runtime: bridges async calls (evidence: `src/any_llm/any_llm.py`)
- OpenAI adapter → Error handling: normalizes failures
- Error handling → SDK exceptions: raises SDK errors (evidence: `src/any_llm/utils/exception_handler.py`)
- OpenAI adapter → Logging: logs activity (evidence: `src/any_llm/providers/openai/base.py`)
