Copy this: fallback checklist
- One interface for every provider, so swapping is configuration, not code.
- Order them: free cloud, then local, then a free offline mock for tests and demos.
- Decide when to switch. Mine only switches before the first word of a streamed reply reaches the user, never in the middle.
- Configure the fallback through environment variables: base URL, model name, a placeholder key.
- Set hard limits: one request at a time, a timeout (mine is 120 seconds), and prompts trimmed to the model’s small context (about 4,000 tokens).
- Measure the fallback before you rely on it.
The story
I wanted a chat product to keep answering if its cloud provider failed. So I added a small local model, a 3-billion-parameter Qwen, behind the same interface. It runs on a CPU-only machine used for my bots, not on my home lab PC.
It works, and it’s slow: about 6 tokens a second, around 5 seconds for a short reply once warm.
The flop was in working out what was actually wrong. The real problem wasn’t an outage. It was the free tier’s per-minute rate limit, and chat started failing at roughly nine messages a minute. A paid tier or a second cloud provider fixes that. A local model at CPU speed can’t carry real traffic. A free local backup for that was possible, but a big job.
Build the fallback so the product can slow down instead of dying, and name the actual bottleneck before choosing the fix.