Getting Started with Any-LLM
Any-LLM is a unified interface that lets you work with language models from any provider using a consistent API. Whether you're using OpenAI, Anthropic, Google, local models, or open-source alternatives, any-llm makes it easy to switch between them without changing your code.
Why Any-LLM?
Provider Agnostic: One API for all LLM providers
Easy Switching: Change models with a single line
Cost Comparison: Compare costs across providers
Streaming Support: Real-time responses from any model
Type Safe: Full TypeScript/Python type support
Installation
%pip install any-llm-sdk[all] nest-asyncio -q
# nest_asyncio allows us to use 'await' directly in Jupyter notebooks
# This is needed because any-llm uses async functions for API calls
import nest_asyncio
nest_asyncio.apply()Setting Up API Keys
Different providers require different API keys. Let's set them up properly:
List Models Across Providers
any_llm can list all available models for an LLM provider - in this case, we are listing out models supported by OpenAI and Anthropic.
Expected output
Provider: openai gpt-4o-mini, gpt-4-0613, gpt-4, gpt-3.5-turbo, gpt-5-search-api-2025-10-14, gpt-realtime-mini, gpt-realtime-mini-2025-10-06, sora-2, sora-2-pro, davinci-002, babbage-002, gpt-3.5-turbo-instruct, gpt-3.5-turbo-instruct-0914...
Provider: anthropic claude-haiku-4-5-20251001, claude-sonnet-4-5-20250929, claude-opus-4-1-20250805, claude-opus-4-20250514, claude-sonnet-4-20250514, claude-3-7-sonnet-20250219, claude-3-5-haiku-20241022, claude-3-haiku-20240307
Generate Text
Let's use one model from each provider to generate text for the same prompt.
Expected Output
Note: The haiku content will be different each time since it's generated by the LLM. This example shows the output format.
Model: gpt-4o-mini-2024-07-18 Response:
Planets spin and dance, In the vast cosmic embrace, Stars whisper their tales.
Model: claude-haiku-4-5-20251001 Response:
Eight worlds circle round, Sun's gravity holds them close— Dance through endless void.
Last updated