AINPM.in / Articles
Builder's notes · Local AI · Cost

Routing AI Requests Across Free Tiers: Builder's Notes

Short answer

A router that spreads AI requests across free tiers is mostly an error-handling policy. Fall back on rate limits, outages, bad keys, retired models and context limits, but return a request's own 4xx without trying others. Cool a provider down for exactly as long as its retry-after or rate-limit headers say. Time out on headers only, so long streams are not cut off, and fall back only before the first streamed byte. In a simulated burst of 120 requests in one minute, OpenFOC AI Router served all 120 and made no calls to a rate-limited provider before its retry-after; one transient 503 then sent most of the minute to the local model. ₹0 per request still costs latency, quality variance and, on some free tiers, your prompts.

Why route across free tiers at all?

Because free AI tiers are generous in total but small one by one. A provider might allow 30 requests a minute on one model, another 50 requests a day, a third a monthly token budget. A developer with a coding assistant open all day hits one of those limits, an outage or a retired model several times a day.

OpenFOC AI Router puts one OpenAI-compatible endpoint on the Mac, at 127.0.0.1:4141, and spreads requests across the free tiers of Groq, Google Gemini, OpenRouter, Mistral and NVIDIA NIM, with local models as the last resort. Building it showed that the router is mostly an error-handling policy, and each rule is a product decision.

1. Decide which errors are the provider’s and which are yours

Response Whose problem? Router action
429 rate limit Provider’s capacity Cool down by its headers, try the next target
5xx, timeout, network error Provider’s health Back off (30 s, growing to 10 min), next target
401, 403 Provider’s key Pause that provider for 10 min, next target
404 retired model Provider’s catalogue Back off, next target
413 context too long That model’s limit Next target, no cooldown
Other 4xx The request Return it to the client; don’t try others

The last row matters most. A malformed request sent down a chain of five providers wastes five quotas and hides a bug in the client. In the router’s tests, an invalid request reaches exactly one provider and comes straight back.

2. Let the provider tell you how long to wait

HTTP already has a field for this: Retry-After (RFC 9110). Many AI providers also send rate-limit headers with what is left and when it resets (Groq’s are documented); OpenRouter reports its reset as an epoch time in milliseconds. The router parses all of these and skips the provider until then.

In a simulated burst of 120 requests in one minute, with a mock Groq allowing 30 and then answering 429 with retry-after: 60, the router made 0 calls to Groq after its limit. Every one of those would have been a wasted round trip.

3. Time out on headers, not on the whole answer

A long streamed answer can run for minutes. If the timeout covers the whole response, the router cuts off good answers. OpenFOC AI Router applies its timeout to the response headers only: a provider that doesn’t start answering in time is skipped, while one that is streaming slowly is left alone.

4. Never splice two models into one answer

Fallback is only safe before the first byte reaches the client. After that, a retry on another provider would join the start of one model’s answer to another model’s continuation. It would look like one answer and be two. The router holds this line for both the OpenAI and the Anthropic-compatible endpoints.

5. Keep the order you meant

A latency-aware strategy is tempting: always pick the fastest target. But the fastest target is often the local model, which would quietly turn “free cloud first, Mac as the safety net” into “Mac first”. OpenFOC AI Router reorders targets only within a tier, never across tiers, and tests for it.

What the simulation taught

The same burst gave a result worth a second look. All 120 of 120 requests were served (Groq 30, Gemini 10, local 80) with 2.42 attempts on average. The local model carried most of the minute because one transient Gemini 503 started a 30-second backoff.

That is the policy working as written, and it shows the trade-off: aggressive backoff protects quota but pushes work, and heat, onto the Mac. The next experiment is a shorter first backoff for a single 5xx, checked against real traffic rather than a mock.

What does ₹0 per request really cost?

  • Latency. Each fallback adds a round trip; the x-ofr-attempts header makes that visible per response.
  • Quality variance. Two models on the same route can answer differently, so pin a route to one model when consistency matters.
  • Your prompts. Some free tiers log prompts or use them to improve products. Gemini’s API terms treat unpaid use differently from paid use. For sensitive work, use a client key restricted to local models.
  • Change. Free tiers move: Cerebras no longer has a standing free tier, and GitHub Models was retired on 30 July 2026. A router has to ship with today’s list, not last year’s.

A checklist for any AI fallback chain

  1. Classify every error as the provider’s or the request’s, and never fall back on the request’s own 4xx.
  2. Honour Retry-After and rate-limit reset headers before inventing your own backoff.
  3. Time out on headers, not on the full stream.
  4. Fall back only before the first streamed byte.
  5. Keep tiers fixed when you balance load.
  6. Return a 503 with an attempts trail when everything fails, and log which provider answered every request.
  7. Re-check provider terms and free-tier limits every month.

The routing code and its 55 tests are in the OpenFOC AI Router repository; the same evals-first thinking is in Evals are the new PRD.

Frequently asked questions

Which errors should an AI router fall back on?

Rate limits (429), server errors and timeouts (5xx), bad or revoked keys (401, 403), retired models (404) and context-length errors (413). Other 4xx errors mean the request itself is invalid, so every provider would refuse it; return those to the client straight away.

How long should a rate-limited provider be skipped?

For as long as the provider says. Read the retry-after header, or rate-limit reset headers where the provider sends them, and skip that provider until then. For outages without such a signal, back off exponentially; OpenFOC AI Router starts at 30 seconds and caps at 10 minutes.

Why not retry a stream on another provider halfway through?

Because the client would receive the start of one model's answer joined to another model's continuation, which reads as one answer but is not. Fall back only before the first byte reaches the client.

Are free AI tiers really free?

In money, within their quotas. They cost in other ways: smaller and changing limits, more latency when requests fall back, answers that vary between models, and on some free tiers your prompts may be logged or used for training. Google's Gemini API terms, for example, treat unpaid use differently from paid use.

Keep reading