Prerequisites
- Python 3.10 or higher
- An API key for at least one provider, or a local server such as Ollama
Install the package
openai, pydantic and tiktoken. It works with openai 2.x and 3.x.
Faster JSON with the fast extra
The fast extra installs orjson, which RouteHub uses for JSON encoding and decoding when it is available.
Set a provider key
RouteHub reads each provider’s key from its environment variable on every call. Set the ones you need:api_key= to any call. See Providers for every variable name.
Verify the install
mock_response returns a real ChatCompletion without a network call or an API key, so you can check the install offline:
Use RouteHub with Swarms
Install Swarms with itsfast extra and every agent makes its model calls through RouteHub instead of LiteLLM, with no code changes:
fast extra, and also installs rustworkx for GraphWorkflow(backend="rustworkx"). Swarms picks RouteHub whenever it is installed. Set SWARMS_LLM_BACKEND=litellm to force LiteLLM, or routehub to require RouteHub. See Installation and Environment setup.
On RouteHub, local OpenAI-compatible servers need /v1 in the agent’s llm_base_url, for example http://localhost:11434/v1 for Ollama.
Next steps
Quickstart
Make your first real call
Configuration
Retries, timeouts, TLS and environment variables