A simple web application demonstrating the any-llm SDK's ability to switch between different LLM providers (Anthropic, Gemini) with direct provider calls.
This is the companion app for this Altered Craft article: Testing Mozilla's any-llm: A Practical Take on Provider Abstraction
- Model Selection: Choose between different LLM providers (Gemini, Claude)
- Chat Interface: Simple, clean chat UI
- Per-Message Token Tracking: See token usage for each message
- Session Metrics: Track cumulative tokens per session (resets when switching models)
- Python 3.13+ with uv installed
- Provider API Keys: Any of your choosing which are supported by Any-llm
-
Clone the repository
-
Create your
.envfile:cp .env.example .env
-
Edit
.envand add your API keys: see: https://mozilla-ai.github.io/any-llm/providers/ for KEY namesANTHROPIC_API_KEY=your_anthropic_key_here GOOGLE_API_KEY=your_google_key_here -
Install dependencies:
uv sync
Start the FastAPI server:
uv run uvicorn app:app --reloadOr use the built-in runner:
uv run python app.pyThe application will be available at: http://localhost:8000
- Open your browser to
http://localhost:8000 - Select a model from the dropdown
- Start chatting!
- Watch the token metrics update after each response
- Switch models to reset the session and start fresh
- Backend: FastAPI (single file
app.py) - Frontend: Vanilla HTML/CSS/JavaScript (in
static/directory) - API Integration: any-llm SDK calling providers directly (no proxy/gateway)
GET /- Serve the web interfaceGET /api/models- List available modelsPOST /api/chat- Send a chat message and get completion
To add or modify available models, navigate to http://localhost:8000/dashboard or edit models_config.json directly

