AI Bakery Gateway sits between your clients and the provider accounts you’ve connected. Your app, agent or coding tool sends an OpenAI Chat Completions, OpenAI Responses, or Anthropic Messages request to one address; the gateway resolves it to an account and model, calls it, and fails over if that call doesn’t succeed.
The request flow
- Resolve the model: a specific model name, a logical model,
auto, or a named routing profile such asfree-code. - Apply hard rules: capability fit, free-tier proof (under FreeOnly), and budget.
- Rank candidates: quota headroom, availability, and measured quality.
- Reserve quota, then call the best-ranked account.
- Fail over on failure, and record enough detail to explain every decision afterwards.
Smart routing, not round-robin
auto: the gateway scores candidates on capability fit, measured quality, availability, remaining quota and freshness, and picks one. You don’t name a model.- Routing profiles ask for the kind of work, not a model name — see the 8 below.
- Quota-aware balancing: with several accounts for the same model, traffic goes to whichever has the most headroom, so one account isn’t drained while another sits idle.
- Bounded failover: a request walks a ranked candidate list up to a configured attempt limit and a first-token deadline, so one slow or dead vendor can’t stall it indefinitely.
- No silent substitution: ask for a specific model and you get that model, or a clear failure — never a quiet swap to something unrelated.
- Equivalent-model matching: the same model offered by two vendors is recognised as one logical model and used as a fallback for the other.
Free-tier protection
FreeOnly ships as the gateway’s default: a request is never sent to a model the gateway cannot currently prove is free. It keeps re-checking that picture — re-reading vendor model lists and recomputing “is this model free for me?” — rather than assuming a past answer still holds. A billing tripwire watches for the case evidence alone can’t catch: if a vendor ever reports a charge on a model the gateway believed was free, the gateway stops using that assignment and raises a critical alert. Expiring trial credit (such as a Cerebras trial) is tracked, and an account with no credit left is excluded before it can fail a request.
Resilience
- Circuit breaker per account and model: a failing unit is taken out of rotation for a cooldown that depends on why it failed — rate limit, timeout, auth, or a withdrawn model.
- The vendor’s own
Retry-Afteris respected. - Streaming safety: a request can fail over before the first token. After the first token, the gateway never silently switches model mid-answer.
- Client cancellation never counts against a provider’s health.
- Honest errors:
402means no free model exists for this request under policy;503means nothing could serve the request right now;429means a tenant used its own budget.
Explainability and operations
Every response carries X-Scheduler-Provider, X-Scheduler-Account and X-Scheduler-Model headers, plus a request id. The bakery command-line tool’s why <request-id> shows every candidate that was considered, why it ranked where it did, and what happened to it. The same CLI covers setup, asking a model directly, listing models, usage, and probing an account (bakery setup, ask, models, usage, probe, tenants, accounts).
A live admin dashboard (Blazor, English and Russian) shows usage, fleet health and routing, a Try page for test requests, a Connect page with ready-to-copy client configuration, and a setup wizard. Alerts go to a webhook, Slack, or Telegram when a free model is lost or gained, a model is withdrawn, or a vendor bills a call unexpectedly. Prometheus metrics, OpenTelemetry tracing, and a ready-made Grafana dashboard with alert rules are included. An MCP server (bakery-mcp) lets an MCP-capable client — Claude Code, OpenCode, Claude Desktop — inspect and diagnose a running gateway directly.