Skip to main content

superrouter

Dual-format FastAPI router that exposes OpenAI-compatible and Anthropic-compatible endpoints on the same app, forwarding to OpenAI-compatible and Anthropic-compatible upstreams and translating request/response formats (including SSE streaming) when needed.

Drop it into any FastAPI app:

from fastapi import FastAPI
from superrouter import SuperRouter

app = FastAPI()

router = SuperRouter(
    providers={
        "openai": {"base_url": "https://api.openai.com/v1", "api_key": "sk-..."},
        "anthropic": {"base_url": "https://api.anthropic.com/v1", "api_key": "sk-ant-..."},
    },
    api_keys=["sk-my-router-key"],  # auth for clients calling YOUR router (optional)
)

app.include_router(router)

Install

With pip:

pip install .
# with server + dev extras
pip install ".[dev,server]"

With uv:

uv add superrouter          # from PyPI once published
uv sync                     # install this repo's deps into .venv
uv sync --extra server      # include the server extra
uv build                    # produce dist/*.whl and dist/*.tar.gz

For local development (editable + dev tools):

# uv
uv sync

# pip
pip install -e ".[dev,server]"
# or
pip install -r requirements.txt

Run the example

cp .env.example .env   # fill in keys
uv run python examples/main.py          # or: python examples/main.py
uv run uvicorn examples.main:app        # alternative

Then:

export OPENAI_BASE_URL=http://localhost:8000/v1
export OPENAI_API_KEY=sk-my-router-key

export ANTHROPIC_BASE_URL=http://localhost:8000/v1
export ANTHROPIC_API_KEY=sk-my-router-key

Endpoints

Method Path Upstream
POST /v1/chat/completions translated to provider
POST /v1/messages translated to provider
POST /v1/completions openai passthrough
POST /v1/embeddings openai passthrough
POST /v1/messages/count_tokens anthropic passthrough
GET /v1/models aggregated from providers
GET /health local health check

Both /v1/chat/completions (OpenAI format) and /v1/messages (Anthropic format) accept either wire format — the router detects the source format and translates to the provider's format, then translates the response (JSON or SSE stream) back.

Configuration

SuperRouter(
    providers={
        "name": {
            "base_url": "https://api.openai.com/v1",  # required
            "api_key": "sk-...",                      # key sent UPSTREAM
            "kind": "openai",                         # "openai" | "anthropic" (inferred from name if omitted)
        },
    },
    default="openai",                     # provider name used when model doesn't match prefixes
    api_keys=["sk-..."],                  # keys CLIENTS must present (None/[] = open)
    timeout=(10, 600),                    # (connect, read) seconds
    prefix="",                            # mount prefix, e.g. "/api"
    tags=["llm"],                         # OpenAPI tags
)

Provider selection per request:

  1. x-super-upstream: <name> header forces a provider.
  2. Model names starting with claude route to the first anthropic provider.
  3. Otherwise the default provider (or the first one).

Client auth (api_keys set): every endpoint except /health requires one of the keys via Authorization: Bearer ..., x-api-key: ..., or ?key=....

Development

uv sync                     # install deps (incl. dev group)
uv run pytest               # run tests
uvx mypy src                # type-check

License

MIT — see LICENSE.

Metadata

Release files for superrouter 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for superrouter 0.1.0
File Size Uploaded Provenance Actions
superrouter-0.1.0.tar.gz 9.7 kB Without provenance Details for superrouter-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for superrouter 0.1.0
File Interpreter ABI Platform Actions
superrouter-0.1.0-py3-none-any.whl Python 3 none any Details for superrouter-0.1.0-py3-none-any.whl

Total release size: 22.5 kB

Release files / superrouter-0.1.0.tar.gz

Download URL superrouter-0.1.0.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
cb835476fa92bc3aaca43aa24d3d6168ea8ac5d3b6f723b3a1fe26f73b29597a
BLAKE2b-256 checksum
How to use checksums
6362aa42cbff7c53c871e43ba143a95b30bd9992abd399f3cafb259d0a9a344d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / superrouter-0.1.0-py3-none-any.whl

Download URL superrouter-0.1.0-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7e9a5eb6385123b462a152c5c596cc1aa6eb77cb9fd2a01ad2d62b2bbd156cd3
BLAKE2b-256 checksum
How to use checksums
3fe9715c164a4bf6cb12790b7af4da1afed57628647a402f3c846ba1123e5db6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for superrouter 0.1.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page