Press play. Each step pops up here as the video reaches it.
Every card says what was done, why, what should happen and what did, then what the gateway was doing underneath. Pick a number to jump to a step.
We gave OpenCode a single ik- key, put a revoked Groq key first in its fallback chain, and recorded what happened. Below is the recording, then every message, check and rule the gateway used.
OpenCode got one normal answer and never saw the 401.
Each step in the video says what is being done, why, and what should happen, then shows the result. As it plays, a card pops up beside it with that step written out and what the gateway was doing underneath.
Every card says what was done, why, what should happen and what did, then what the gateway was doing underneath. Pick a number to jump to a step.
What actually went over the wire. OpenCode only ever talks to the gateway on your computer; the gateway talks to the providers.
auto · key ik-••••ik- key, orders the chain. The revoked Groq key is Unchecked, so it goes first.ik-x-infinitykeys-attempts: 2 · logged as failover_servedx-infinitykeys-attempts: 1 · logged as servedWhy the second request skipped Groq without anyone touching a setting: before every request, the gateway sorts the chain by how each key has been doing.
The eight checks every request passes through on your computer, in order, and the answer you get when one of them stops it.
Accepts the universal ik- key, a unique per-agent key, or the network key for Tailscale.
Stops with Any other key gets 401. Ten failed tries in a minute from one address pause that address.
Unique and network keys may only send chat, completion, response, embedding and message requests, as a plain JSON body.
Stops with 403 for other endpoints, 400 for a malformed body. The universal key on this computer is not limited here.
Checks a unique key’s spend budget and its allowed models and providers.
Stops with 429 when the budget is used up, 403 for a model the key may not use.
Checks your overall spend cap. Depending on your setting it blocks, or allows free-tier keys only.
Stops with 429 when the cap blocks, or when no free-tier key is left.
Takes the fallback chain, or a smart-routing alias such as ik:cheap, and drops keys this caller may not use.
Stops with 503 if the chain is empty.
Sorts the candidates into the four groups shown above.
Stops with Nothing stops here.
Returns an identical recent answer without calling a provider.
Stops with Off by default.
Swaps in the real key and the model (auto becomes that entry’s model), forwards the request, and on a failure records it and moves to the next key.
Stops with Only when every key has failed: you get the last provider’s error, with any stored key redacted from it.
The gateway reads the provider’s answer and decides what it means for that key. The request itself always moves on.
| Provider answers | What it means | Key status becomes | Waits before using the key again |
|---|---|---|---|
| 401 or 403 | The provider rejected the key itself. | Invalid, “Rejected during a gateway request” | None. It moves to the back of the order. |
| 402, or an out-of-credit message (400, 403 or 429) | The key has no credits or quota left. | Out of credits | 10 minutes, or the provider’s Retry-After (up to 1 hour) |
| 429 | Rate-limited. | Rate-limited | 60 seconds, or the provider’s Retry-After (up to 1 hour) |
| 400, 404, 405 or 422 | This provider can’t take this particular request. | Unchanged: the key is fine | None |
| 5xx, no answer, or a timeout | The provider is down or hung. | Provider down | 15 seconds, or the provider’s Retry-After (up to 1 hour) |
Three places show what happened, so you never have to take the agent’s word for it. None of them ever holds a secret.
Sent back to the agent with every answer. The provider header names whichever key answered.
x-infinitykeys-provider: <provider>
x-infinitykeys-attempts: 2Attempts counts the keys tried, including the one that answered. Unique and network keys see these two headers but never the provider’s account headers or your key names.
In Diagnostics, newest first. These are the two requests from the recording.
served Coarena
attempts: none
failover_served Coarena
tried: Groq (revoked demo key)
status: 401Each entry keeps key names, providers and status codes. If every key fails, the entry is all_failed with the full attempt list.
On the key’s row in the vault, until you act on it.
Groq (revoked demo key)
Invalid
Rejected during a gateway request
Get a new Groq key ↗ SwapNothing is deleted for you. If the key works again later, the gateway marks it Valid on its own.
The same diagrams as the GitHub README: where the gateway sits, how failover works in general, and what protects the keys at rest.
Agents send requests to one local gateway with an ik- key. The gateway decrypts the real provider key in memory from vault.enc and your local keystore, and swaps it in on the way out.
The general case of the recording: one key out of credits, the next rate-limited, the third answers. The agent sends once and receives once.
From the per-agent keys an agent holds, down through the gateway and the encrypted vault file, to the data key in the macOS Keychain or local key file.
The recording used a throwaway vault on its own port. On your computer the gateway is at 127.0.0.1:8790. This is the whole OpenCode setup; any agent that speaks the OpenAI API works the same way.
{
"provider": {
"infinitykeys": {
"npm": "@ai-sdk/openai-compatible",
"name": "InfinityKeys",
"options": {
"baseURL": "http://127.0.0.1:8790/v1",
"apiKey": "{env:INFINITYKEYS_KEY}"
},
"models": { "auto": {} }
}
},
"model": "infinitykeys/auto"
}curl -s http://127.0.0.1:8790/v1/chat/completions \
-H "Authorization: Bearer $INFINITYKEYS_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"auto","messages":[
{"role":"user","content":"Hello"}]}' \
-D - | grep -i x-infinitykeysCopy the universal key from InfinityKeys → Universal Key into INFINITYKEYS_KEY. The last line prints which provider answered and how many keys it took.