Product · AI API gateway
Routehook
One API, one key and one prepaid balance for text, image and video models from every major provider.
- API platform · Billing
- 2026

About Routehook
Introduction
Teams building AI products end up integrating provider after provider: a different SDK, key, bill and rate limit for every model they want to try. Routehook puts one OpenAI-compatible endpoint in front of all of them. Chat, embeddings, images and video go through a single base URL; long-running generations run as queued jobs with webhooks and failover; and every request is charged from a prepaid balance on an append-only ledger, so a customer can never be billed twice or spend past their balance.
Details
- Project
- Routehook
- Timeframe
- 2026
- Type
- API platform · Billing
- Live
- routehook.ai
- Next.js
- NestJS
- PostgreSQL
- Redis
- Drizzle
- Stripe
- better-auth
- Docker
- Problem
- Using several AI providers means several integrations, keys and invoices — and switching models usually means rewriting code. Image and video models add a second problem: a generation can run for minutes, fail halfway, and still have to be billed correctly.
- What we built
- A gateway that speaks the OpenAI and Anthropic wire formats, with provider adapters behind it, async jobs for image and video, per-key rate limiting, routing and failover between providers, a hold-then-settle billing ledger, a customer dashboard with a live playground, and an admin console.
- Outcome
- Live at routehook.ai with a public model catalogue and published per-request pricing.
- provider adapters behind one endpoint
- 11
- wire formats: Chat Completions, Responses and Anthropic Messages
- 3
- routing strategies to choose from, per model
- 5
- tools on the MCP server
- 16
Inside the dashboard.
The console a customer runs their AI traffic from, rebuilt here in code from its own screens. Pick a page, or click the sidebar.
Every model, at your price
One catalogue of text, image, video, audio, embedding and rerank models, each with the customer’s own price and how much they have used it in the last 30 days.
- Search by name or model id
- Filter by type, or Used by me
- Live or Coming soon
- Try it, or ask for a discount
Recreated from the dashboard’s interface. Labels and columns are Routehook’s own; the account, requests, prices and numbers are samples, and the images are CC0 photographs standing in for model output.
The parts, up close.
The gateway behaviour behind the dashboard, at full size.
Gateway
Change the base URL, keep the SDK
The gateway speaks three wire formats, streaming or not, so an existing OpenAI or Anthropic client works by swapping two values.
Response
The cost comes back with the answer
Every response carries what it cost, which provider answered, how many attempts it took and whether a fallback stepped in.
Ledger
Hold, then settle
The worst-case cost is held before a request leaves, and a database constraint refuses any hold the balance cannot cover. Afterwards the hold settles to the real cost.
Queue
Long generations run as jobs
An image or video request returns a job at once. It can be polled, followed or cancelled, and a signed webhook fires when it finishes — retried with backoff if the receiver is down.
Limits
Limits that hold across processes
One atomic script in Redis keeps a bucket per key, so every API process sees the same count.
Errors
Eight errors, named plainly
Every failure maps to one stable code, so a client can tell a bad key from an empty balance from a provider that is down.
Notifications
Seven alerts, two channels
Each alert can reach the dashboard, the inbox, both or neither, and the choice saves as it is made.
What went into it.
- 01
Unified gateway
One /v1 endpoint for chat, completions, embeddings, rerank, audio, images and video, with adapters for Anthropic, Gemini, OpenAI-compatible providers and the image, video and audio model hosts.
- 02
Billing you can trust
A prepaid balance on an append-only ledger with hold-then-settle charging, usage per key and a per-request cost log. Stripe and crypto top-ups via webhooks.
- 03
Growth tooling
Server-side ad conversion tracking for Meta, Reddit, X, Google Ads and GA4, plus an MCP server with OAuth for agent access.
How it is built.
The running parts
- Gateway API
- NestJS, forked across CPU cores, with Drizzle for data and better-auth for sessions and API keys.
- Three web apps
- The public site with docs and the model catalogue, the customer dashboard and the admin console, all Next.js, sharing one package of request and response schemas.
- PostgreSQL
- Accounts, the ledger, the request log and the job queue itself. There is no separate message broker to run.
- Redis and object storage
- Redis holds rate-limit buckets and realtime fan-out. Generated media goes to S3-compatible storage.
- Deployment
- Docker Compose on Dokploy, built from source on every push to main, behind Traefik with automatic certificates.
The hard parts
- 01
Never spend more than the balance
Before a request leaves, its worst-case cost is reserved as a hold, and a database constraint refuses any hold the balance cannot cover. Afterwards the hold settles to the real cost. A sweeper releases holds a crash left behind, and a reconciler charges jobs that finished but never settled.
- 02
A ledger nobody can edit
A database trigger rejects every update and delete on ledger entries, and it is the only thing allowed to write the settled balance. The application cannot quietly change history even with a bug.
- 03
Failover without charging twice
A stream is committed to a provider at its first byte. Before that, a bad request stops the chain, an auth failure skips only that provider, and a circuit breaker takes a failing provider out of rotation and lets a single probe test it again.
- 04
Rate limits that hold across processes
Limits run as one atomic script in Redis with a bucket per key, so every API process sees the same count and a burst cannot slip between two of them.
- 05
A job queue without a broker
Workers claim jobs straight from PostgreSQL with row locks that skip what another worker already holds. Outgoing webhooks are signed, retried with backoff, and checked against the resolved address so they cannot be pointed at internal systems.
Want to see more?
Start here
Have a problem worth solving?
Tell us what is slow, manual or missing. You will hear back within one working day — then get a written scope and a fixed quote, or an honest no.
- # New project brief
- ## What is slow, manual or missing?
- - [x] Written scope
- - [x] Fixed quote
- - [x] Or an honest no


