mozilla-ai/any-llm

Communicate with an LLM provider using a single interface

What it solves

It addresses the fragmented landscape of LLM provider interfaces. Because different providers use slightly different parameter names and response formats, developers often have to rewrite code when switching models. any-llm provides a single, unified interface to access multiple LLM providers without needing to change the core application logic.

How it works

The library acts as a light wrapper that leverages official provider SDKs to ensure maximum compatibility. It offers two primary ways to interact with models:

  1. Direct API Functions: A stateless completion function ideal for scripts and notebooks.
  2. AnyLLM Class: A stateful approach that reuses clients and connection pooling, recommended for production applications.

It supports a provider:model string format or separate parameters to route requests to providers like OpenAI, Anthropic, Mistral, and Ollama, and it can also connect to custom OpenAI-compatible endpoints.

Who it’s for

It is designed for developers who want to switch between different LLM providers easily, those migrating from LiteLLM, and teams building framework-agnostic AI applications that need to avoid dependency on hosted proxy servers.

Highlights

  • Unified Interface: Switch providers by changing a single string.
  • Official SDK Integration: Uses official SDKs rather than reimplementing interfaces to maintain better compatibility.
  • Proxy-free: Operates directly between the code and the provider without requiring a hosted proxy.
  • Developer Experience: Includes full type hints for IDE support and clear error messages.

Related

  • Project
  • Project
  • Project
  • Project
  • Project