How mozilla-ai/any-llm works
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: openai/base.py OpenAI adapter · any_llm.py AnyLLM client · anthropic/base.py Anthropic adapter · api.py Direct API
Components 17
SDK entry points
- Direct API
src/any_llm/api.py - AnyLLM client
src/any_llm/any_llm.py
Provider dispatch
- Provider registry
src/any_llm/providers/registry.py
Provider adapters
- Provider adapters
src/any_llm/providers - OpenAI adapter
src/any_llm/providers/openai/base.py - Anthropic adapter
src/any_llm/providers/anthropic/base.py
Shared runtime
- Typed API schemas
src/any_llm/types - Completion types
src/any_llm/types/completion.py - Message types
src/any_llm/types/messages.py - Responses types
src/any_llm/types/responses.py - Structured output
src/any_llm/utils/structured_output.py - Async runtime
src/any_llm/utils/aio.py - Error handling
src/any_llm/utils/exception_handler.py - SDK exceptions
src/any_llm/exceptions.py - Logging
src/any_llm/logging.py
Other components
- Application developer
- LLM providers
Connections 17
- Application developer → Direct API: calls directly
README.md - Application developer → AnyLLM client: creates client
README.md - AnyLLM client → Provider registry: resolves provider
src/any_llm/providers/registry.py - Direct API → Provider adapters: selects provider
- Provider registry → OpenAI adapter: builds compatible class
src/any_llm/providers/registry.py - Provider adapters → LLM providers: sends requests
README.md - OpenAI adapter → LLM providers: calls SDK
- Anthropic adapter → LLM providers: calls SDK
- AnyLLM client → Typed API schemas: uses request types
src/any_llm/any_llm.py - OpenAI adapter → Completion types: converts results
src/any_llm/providers/openai/base.py - Anthropic adapter → Message types: converts results
src/any_llm/providers/anthropic/base.py - AnyLLM client → Structured output: parses output
src/any_llm/any_llm.py - OpenAI adapter → Structured output: checks format
src/any_llm/providers/openai/base.py - AnyLLM client → Async runtime: bridges async calls
src/any_llm/any_llm.py - OpenAI adapter → Error handling: normalizes failures
- Error handling → SDK exceptions: raises SDK errors
src/any_llm/utils/exception_handler.py - OpenAI adapter → Logging: logs activity
src/any_llm/providers/openai/base.py