Repository navigation
Releases
v0.2.1: failover now handles a bad Gemini key
This release fixes a failover bug found by testing against the real
provider APIs.
Fixed
- A bad Gemini API key now falls back to the next provider. Gemini
reports a bad key as a400error, which ModelSwitch treated as a
problem with the request itself, so it stopped without trying other
providers. It now reads the specific reason Gemini gives and moves on
to the next model in the alias.
Other 400 errors still stop the request, so a prompt one provider
refuses isn't sent on to the others. Records still show Gemini's real
400, now with the code API_KEY_INVALID.
Upgrading
No database migration or config changes are needed.
This is a pre-1.0 release, so details may change.
v0.2.0: per-key limits, budgets, and cost estimates
ModelSwitch can now be shared with other users: each API key has its own
limits, and you can see and cap what it spends.
What's new
- Rate and concurrency limits: each key is limited in how fast it can
send requests and how many it can have running at once. - Monthly budgets: give a key a limit in USD, and it stops at about
that amount until the next month. - Cost estimates: set versioned prices, and each request records an
estimated cost. Old estimates stay the same when prices change. - Key expiry and live keys: keys can stop working on a set date, and
ms_live_keys are easy to tell apart fromms_dev_keys.
Good to know
- Budgets are firm, not exact. Requests already running can take a key
slightly over its limit. - Costs are estimates from token counts the provider reported. Failed
attempts aren't counted, so your real bill can be higher. - Keys have no budget unless you set one.
- A key with a budget can only use models that have a price.
- Rate and concurrency limits are counted per server.
Upgrading
Run modelswitch migrate before starting this version.
This is a pre-1.0 release, so details may change.
v0.1.0: one API for Groq, Gemini, and Ollama, with automatic failover
ModelSwitch is a self-hosted gateway written in Rust. Your app calls one
API, and ModelSwitch handles the providers behind it. If one fails, your
request moves to the next.
This is the first release. It's ready to try with your own apps, but
not ready to expose to the public (see Limitations).
Highlights
One API, several providers. Send requests to POST /v1/generate
using Groq, Google Gemini, or a local Ollama model. Changing provider is
a config change, not a code change.
Automatic failover. Define an alias such as fast with an ordered
list of models. Brief failures get one retry, then ModelSwitch moves
down the list. Every request has a limit on attempts and total time, so
it can't hang or retry forever. Need one exact model? Pin it with
groq/openai/gpt-oss-20b, and it will never switch.
See what happened. Every response tells you which provider answered
and how many attempts it took. Each request and attempt is saved to
PostgreSQL with its outcome, latency, and token counts as reported by
the provider. Prometheus metrics are available on a separate internal
port.
Private by default. Prompts and responses are never logged or
stored. API keys are stored only as hashes, and revoking one takes
effect immediately.
Get started
You need Rust and PostgreSQL. The README walks through
setup, and the built-in echo provider lets you try the API without any
provider account.
Limitations
- Don't expose it to the public yet. There are no rate limits or
spending caps, so anyone with a valid key can use your provider
credit without limit. - Text only, with no streaming.
- No cost estimates yet. Token counts are recorded.
- Ollama support hasn't been tested against a live server yet.
- If a client disconnects mid-request, that request isn't recorded.
- On Gemini's free tier, the newest models can be too slow for the
default timeout.
Rate limits and spending caps are planned next. See the
roadmap.