r/SelfHosting • • 4h ago

DiRouter – a self-hosted LLM gateway with provider fallback, circuit breakers, rate limits and budgets (Apache-2.0)

Post image
1 Upvotes

Hi r/selfhosted,

I built DiRouter, a gateway that sits between your apps and LLM providers (OpenAI, Anthropic, Gemini, Bedrock, Vertex, or any OpenAI-compatible server). Your apps talk to one endpoint; the gateway handles the operational mess.

[One or two sentences: why you built it / what problem you hit yourself.]

What it does:

- Falls back to another provider or API key when one fails (529, 5xx, quota), before any byte reaches the client

- Circuit breakers per provider and per model, so a dead provider stops getting retried

- Distributed rate limits (RPM/TPM) in Valkey, with a local mode if Valkey goes down

- Budgets per key, team and project

- Speaks both OpenAI and Anthropic formats and translates in either direction

- Admin dashboard, SSO/SCIM, audit log — all included, no enterprise tier

Self-hosting:

- Docker Compose; needs PostgreSQL and Valkey

- `make quickstart` brings up the whole stack against a mock provider and sends a first request, so you can try it without an API key

- The gateway never queries the database on the hot path: if the control plane goes down, traffic keeps flowing on the last config snapshot

- Overhead measured at +1.1 ms p50 / +2.8 ms p99 at 250 RPS (method and caveats in the repo)

Repo: https://github.com/alirezariahi/dirouter

It's honest about where it's behind: LiteLLM has a much bigger provider list and community, and the README has a comparison table with LiteLLM and Portkey. Feedback, bug reports and "this cell in your comparison is wrong" are all welcome.