Resilience
Never hit limits
Auto-fallback across providers in milliseconds. Quota out? The next provider takes over — zero downtime.
AI routing infrastructure
A control layer between your AI tools, coding agents and model providers. Auto-fallback, quota-aware routing, local or remote.
$ blackriver-gateway start
› claude ........ ok
› quota out → glm $0.50
› switched in 8ms
› openai, gemini, mistral ... ready
The promise
Resilience
Auto-fallback across providers in milliseconds. Quota out? The next provider takes over — zero downtime.
Cost
Route by cost, capability, quota or policy. Stops premium endpoints from being used for tasks that don't need them.
Pricing
Self-host for free. 90+ free-tier providers onboard by default. No credit card. No vendor lock-in.
Compatibility
OpenAI-compatible endpoint. Claude Code, Codex, Cursor, Cline, OpenCode, Roo, Copilot — point, route, build.
Surface
Provider, model, fallback, quota, cost, latency and policy are decided at the gateway — not inside every tool.
Operations
Local, remote or private. Audit logs, observability, enterprise controls. Built for teams shipping AI in production.
Routing
BlackRiver Gateway gives teams one endpoint for many providers. Requests can be routed by cost, model capability, quota, latency, availability or internal policy.
When one provider fails, hits limits or becomes too expensive for the task, the gateway moves traffic — without forcing every tool to be reconfigured.
01
Use the accounts and subscriptions your team already pays for before sending traffic elsewhere.
02
Move requests to alternative providers when rate limits, outages or quota exhaustion hit.
03
Select models based on task value instead of always defaulting to premium endpoints.
Providers we route through
From the largest commercial model APIs to free tiers, local models and self-hosted backends. New providers ship in days, not quarters.
Quickstart
Step 1
One command. The gateway starts on localhost with sensible defaults.
$ npm i -g @blackriver/gateway
$ blackriver-gateway start
› listening on http://localhost:8080
Step 2
Paste a key or pick a free tier. Quota, cost and capability are detected automatically.
# any of these, mixed together
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GEMINI_API_KEY=AIza...
OPENROUTER_API_KEY=sk-or-...
# or pick a free tier
FREE_PROVIDERS=pollinations,longcat
Step 3
Set the base URL. Existing OpenAI clients work without code changes.
// any OpenAI-compatible tool
baseURL = "https://gateway.blackriver.ai/v1"
apiKey = "br_..."
Features
Engine
Auto-combo engine fans a request across providers, merges results and picks the best answer by score, cost or policy.
State
Persistent memory, semantic recall and reusable skills. Context survives model, provider and tool swaps.
Resilience
Provider, model and account fallbacks. If one route is blocked, the next one tries — automatically, in milliseconds.
Cost
Tracks free-tier usage across providers. Routes around exhausted quotas so paid traffic is the last to be used.
Efficiency
Cuts 15–95% of eligible tokens with stacked RTK and Caveman-style rewrites before requests leave the gateway.
Protocol
95 MCP tools exposed to agents. Let coding agents and copilots drive the gateway themselves.
Protocol
Agent-to-agent handoff. External agents can negotiate models, context and policy with the gateway directly.
Routing
Cost-first, capability-first, round-robin, weighted, sticky-session, latency-aware, policy-aware and more.
Tools
Point Claude Code, Codex, Cursor, Cline, OpenCode or any OpenAI-compatible client at the gateway. Routing, fallback and policy become a setting, not a refactor.
Coding agents
Route coding traffic through one controlled layer. Keep using your existing IDE.
AI workflows
Avoid brittle one-provider workflows. Fallback, retry and policy are handled at the edge.
Copilots
Standard OpenAI-compatible endpoint. Drop in, route out.
Self-hosted
Use the gateway as the routing brain for local and private deployments.
Why
Optionality
Every provider becomes a route. Switching is a config change, not a project. The gateway treats each model the same.
Resilience
When one provider goes down, the gateway keeps your IDE, agents and copilots working — automatically, in the background.
Economics
Use existing subscriptions, free tiers and cheaper models first. Premium endpoints are reserved for tasks that need them.
Compare
| Capability | BlackRiver Gateway | LiteLLM | Portkey | OpenRouter |
|---|---|---|---|---|
| OpenAI-compatible endpoint | Yes | Yes | Yes | Yes |
| Self-hostable | Yes — local or remote | Yes | Cloud-first | No |
| Auto-fallback across providers | 3-layer | Manual | Manual | Yes |
| Free-tier routing | 90+ providers | No | No | Limited |
| MCP server (95 tools) | Yes | No | No | No |
| A2A protocol | Yes | No | No | No |
| Token compression | 15–95% | No | No | No |
| Memory & skills | Built in | No | No | No |
| TokenOptimizer integration | Native | No | Webhook | No |
| Pricing model | Free self-host | Free self-host | Usage-based | Per-token |
Architecture
The gateway exposes an OpenAI-compatible API surface while routing traffic to multiple provider backends behind the scenes.
// any OpenAI-compatible client
const client = new OpenAI({
baseURL: "https://gateway.blackriver.ai/v1",
apiKey: process.env.BLACKRIVER_GATEWAY_KEY,
});
const response = await client.chat.completions.create({
model: "auto:code",
messages: [{ role: "user", content: "Refactor this module" }],
});
// Gateway decides:
// provider, model, fallback, quota, cost, policy.
Where it runs
01
npm
Local install, runs on any Node host.
02
Docker
Single image, single port, zero config.
03
Desktop
Native app for macOS, Windows, Linux.
04
ARM
Apple Silicon, Raspberry Pi, Graviton.
05
Termux
Run the gateway on an Android phone.
06
PWA
Browser-only dashboard for quick routing.
07
OpenCode plugin
Drop-in for OpenCode-based IDEs.
08
Source
Build it yourself. MIT-style license.
Combos
A single request can fan out across multiple models in parallel, get scored, deduplicated and merged. The gateway picks the answer that best fits the policy you defined — without your tool knowing.
Request
"Refactor this module"
Fan-out
3 models in parallel
Score
Best answer by policy
Free tier
By combining free tiers across providers, the gateway exposes close to 1.6 billion free tokens every month — without spinning up a single paid account.
90+
Free-tier providers onboard by default.
11
Free-forever providers, no rate cliff.
1.6B
Combined free monthly tokens.
$0
Cost to start. Self-host forever.
Compression
TokenOptimizer-aware compression runs at the gateway. System prompts, tool outputs and long contexts are rewritten before they leave — typically 60% on tool-heavy sessions, up to 95% on chatty ones.
Resilience
Layer 1 — Provider
If a provider returns an error, hits a rate limit or times out, the gateway moves the request to the next configured provider in milliseconds.
Layer 2 — Model
If a specific model is degraded or removed, the gateway re-routes to the next model in the capability tier — without the client knowing.
Layer 3 — Account
If a subscription is exhausted, the gateway shifts traffic to another account, free tier or organization pool — also without the client knowing.
Proxy
1 — Sticky
Pin a session, model or tool to a specific account or provider to preserve state and avoid context churn.
2 — Stealth
Header rewriting, fingerprint rotation and traffic shaping keep sessions under the radar of aggressive rate limits.
3 — Private
Run entirely on your own hardware, on your own VPC or on a single developer laptop. No telemetry, no lock-in.
Dashboard
Inspect traffic, replay requests, watch provider health, manage keys and audit every call. The gateway ships with a first-party UI — and a CLI for teams that prefer it.
claude-sonnet → claude
last 1h · 1,284 req
p95 412ms
gpt-4o → openai
last 1h · 921 req
p95 380ms
gemini-1.5 → google
last 1h · 612 req
p95 290ms
glm-4.5 → zhipu
last 1h · 410 req
p95 540ms
Inspect
Step through headers, body and routing decisions. Rerun against a different provider, model or policy.
Audit
Every call, key rotation, fallback and policy change is logged. Export to TokenOptimizer for cost analysis.
CLI
Manage providers, policies and secrets from the terminal. Scriptable. Script-friendly.
Protocols
MCP
95 Model Context Protocol tools exposed to agents. Inspect, replay, route, fallback, switch policy — all from inside the agent.
A2A
Agent-to-agent handoff. External agents negotiate models, context and policy with the gateway directly over a typed protocol.
Cloud agents
Cloud-hosted agents can connect, register and use the gateway as a shared routing brain across the team.
Platform
Services
Memory, cache, queue, scheduler and skills are embedded services — not external systems to wire up.
Context
Plug in documents, embeddings and indexes. The gateway injects the right context into the right model at the right time.
Safety
PII redaction, prompt guards and per-team policy live at the edge — not in every tool's prompt.
Engagement
Surface provider health, savings and fallback wins to the team. Make routing decisions visible and rewarding.
Enterprise
The same gateway a single developer installs in 30 seconds becomes the AI routing layer for the whole company — with policy, audit and observability in place.
Policy
Define allowed providers, model tiers and fallback behavior by team, tool or project. Enforced at the edge.
Visibility
See which tools, agents and workflows are consuming AI budget through the gateway. Per-team, per-project, per-user.
Integration
Gateway traffic feeds cost intelligence, audit reports and optimization dashboards inside TokenOptimizer. Same company, two products.
Operations
Private deployments, SSO, audit-grade logging, signed builds and dedicated support for teams that need more than self-host.
Company
A UK company created to build, own and operate AI products and infrastructure. The gateway is one of its products.
Contact
Gateway deployment, provider routing, enterprise controls, private forks and integration with TokenOptimizer.
A note on lineage
BlackRiver Gateway is a BlackRiver AI product. The architecture, UX patterns and provider-fallback model draw from open-source AI router projects in the wider community. Original licenses, attribution and notices are preserved in the public repository and documentation.