This release is a pre-release and may not be stable for production use.
theagentrouter
Call AI models from your agent with LiteLLM's API.
Every call goes through Agent Router, an open-source AI gateway, which handles fallbacks, retries and request limits.
Alpha: names and behaviour may change before 1.0.
Quick start
pip install theagentrouter
export ANTHROPIC_API_KEY=...
import theagentrouter
resp = theagentrouter.completion(
model="anthropic/claude-sonnet-4-5",
messages=[{"role": "user", "content": "Summarise yesterday's refunds"}],
)
print(resp.choices[0].message.content)
The first call starts a local gateway on your computer, and the gateway calls the provider with your key. On Windows, Intel Macs and older Linux there is no local gateway; use a remote one instead (see Install).
Why use it
- Already using LiteLLM? Change one import. Functions, arguments, responses and errors stay the same.
- Fallbacks and retries run in a gateway, not in your process. Define a route once, and every program on the computer uses it.
- Google ADK and the OpenAI Agents SDK work without LiteLLM installed.
- Point it at your company's gateway with two environment variables. Provider keys then stay on that gateway, not on laptops.
Examples
| You want to | Example |
|---|---|
| Make one call | 00_two_liner.py |
| Move a LiteLLM script over | 11_from_litellm.py |
| Fall back to another model when one fails | 07_fallback.py |
| Retry on rate limits and server errors | 08_retry.py |
| Stream, use tools, get JSON back | 03_streaming.py, 04_tool_use.py, 06_structured_output.py |
| Run a Google ADK or OpenAI Agents SDK agent | 16_adk_agent.py, 17_openai_agents.py |
| Send calls to your company's gateway | 15_through_a_gateway.py |
All twenty-one, with the keys each one needs: examples/.
Coming from LiteLLM
from theagentrouter.compat import litellm # was: import litellm
Change this one import; the rest of your code stays the same. Some LiteLLM functions are not in the SDK, and some arguments are ignored with a warning. The full list: docs/coming-from-litellm.md.
Fallbacks and retries
A route is a model name you choose, with the models behind it in order. The local gateway calls the first model, retries it if it fails, then moves on to the next one:
import theagentrouter as ar
ar.route("chat", primary="openai/gpt-4o", fallbacks=["anthropic/claude-sonnet-4-5"], retry=ar.Retry(attempts=2))
ar.completion(model="chat", messages=[{"role": "user", "content": "hi"}])
Here a call to chat goes to openai/gpt-4o. If it cannot be reached or answers with 429, 500, 502, 503 or 504, the gateway retries it up to 2 more times, then tries anthropic/claude-sonnet-4-5 the same way. Other errors, such as 401, are not retried.
- A route can also limit requests:
limit=ar.Limit(60, per="minute")lets 60 requests a minute through and answers the rest with aRateLimitError. - Routes are saved in
~/.agentrouter/routes.json, so every program on this computer can use them. - Routes work with the local gateway only. With
AGENTROUTER_BASE_URLset, set up fallbacks on that gateway instead. Routerfromtheagentrouter.compat.litellm, with LiteLLM'sfallbacksandnum_retries, is turned into routes.
Details: Routes.
Agent frameworks
| Framework | How |
|---|---|
| Google ADK | install_as_litellm(), then ADK's LiteLlm model |
| OpenAI Agents SDK | install_as_litellm(), then the Agents SDK's LitellmModel |
install_as_litellm() is in theagentrouter.compat. It makes import litellm load this SDK, so neither framework needs LiteLLM installed. Details and examples: docs/frameworks.md.
Install
pip install theagentrouter
This installs the SDK and the local gateway. The local gateway is Agent Router's aigw program, about 80 MB, and it runs on:
- macOS 13 or newer on Apple chips
- Linux with glibc 2.36 or newer, on x86-64 or Arm
On any other computer (Windows, Intel Macs, macOS 12 or older, Alpine Linux, Linux with glibc older than 2.36) there is no local gateway, so the same command installs the SDK alone. Calls then need a remote gateway (below).
If your code will use a remote gateway, for example on a server, in a container, in a serverless function or in CI, install the SDK alone and skip the 80 MB:
pip install theagentrouter-core
Both packages are imported the same way: import theagentrouter.
Using a remote gateway. To send calls to an Agent Router gateway that your team or company runs, set its address and key:
export AGENTROUTER_BASE_URL=https://gateway.acme.example/v1
export AGENTROUTER_API_KEY=...
With these set, calls go to that gateway, the local gateway never starts, and the provider keys stay on the remote gateway. This works on every computer.
The local gateway keeps running after your program ends, and every program on this computer that uses the SDK shares it. Its files are in ~/.agentrouter/local-gateway/ (or AGENTROUTER_HOME/local-gateway/): config.yaml, state.json and aigw.log. To stop it (the next call starts it again):
python -c "from theagentrouter import local_gateway; local_gateway.stop()"
Installing from source before the first release, checking the install, upgrading and removing: docs/install.md.
Documentation
| Page | What it covers |
|---|---|
| Install | The SDK, the local gateway, checking it works, upgrading, removing |
| Usage | Models and keys, parameters, streaming, async, tools, responses, errors, cost, gateways, settings |
| Coming from LiteLLM | What works the same, what is missing, what is ignored, a checklist |
| Agent frameworks | Google ADK and the OpenAI Agents SDK |
| How the local gateway works | For contributors: packages, config, routing, tests, what is open |
For coding agents
llms.txtandllms-full.txt: the docs and examples in the llms.txt format, for coding agents and AI search.skills/: agent skills (SKILL.md).migrate-from-litellmmoves a project off LiteLLM;theagentrouterwrites new code with the SDK. Copy a folder into your agent's skills folder (for Claude Code,.claude/skills/), then ask it to "migrate this project from LiteLLM to theagentrouter".
More
- DEVELOPMENT.md: what is where in this repository, setting up, tests, the framework tests, real-provider checks, releases.
- CONTRIBUTING.md, SECURITY.md, CHANGELOG.md.
Design
- Only what agent frameworks use. The SDK has a LiteLLM function or setting only if an agent framework calls it. So there is no image generation, speech, video, files or batches.
- Agent Router handles the calls. The gateway does fallbacks, retries, request limits, provider keys and logging. The SDK only does what a gateway can't, like building LiteLLM's response objects or running your callbacks.
- Same API as LiteLLM. Same function names, arguments, responses and errors.
License
Metadata
Release files for theagentrouter-core 0.1.0a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| theagentrouter_core-0.1.0a1.tar.gz | 165.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| theagentrouter_core-0.1.0a1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 227.0 kB
Release files / theagentrouter_core-0.1.0a1.tar.gz
| Download URL | theagentrouter_core-0.1.0a1.tar.gz |
|---|---|
| Size | 165.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6b18d4352f3fa53a475343b9810adaf82699aa52deb408be7b9fc0c9703f274c
|
|
BLAKE2b-256 checksum How to use checksums |
2ae1f21d9a8ed79a2a18f11f3651eb41f6e51dc08c3d38938092b47852179ef0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.
Transparency logRelease files / theagentrouter_core-0.1.0a1-py3-none-any.whl
| Download URL | theagentrouter_core-0.1.0a1-py3-none-any.whl |
|---|---|
| Size | 61.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
244c8f89efd8a328c6484a2335cd8823f00e6706e1bf47dfd149d909640975f6
|
|
BLAKE2b-256 checksum How to use checksums |
d14b0a24a79731ed13a0f5d4e2cc5c229144b89d254b6b2b8af023bdb1738950
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.
Transparency log