Skip to main content

Prerequisites

  • Python 3.10 or higher
  • An API key for at least one provider, or a local server such as Ollama

Install the package

RouteHub has three direct dependencies: 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 ROUTEHUB_USE_ORJSON=0 to fall back to the standard json module without uninstalling orjson.

Set a provider key

RouteHub reads each provider’s key from its environment variable on every call. Set the ones you need:
You can also pass api_key= to any call. See Providers for every variable name.
Keep keys in a .env file or a secrets manager and never commit them. RouteHub never writes keys to logs, including with set_verbose=True.

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 its fast extra and every agent makes its model calls through RouteHub instead of LiteLLM, with no code changes:
The extra requires RouteHub 0.2.0 or newer, with RouteHub’s own 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