Out of credit. Not out of service.

One fetch for the OpenAI, Anthropic and AI SDKs. When a billing organization runs dry, requests move to your next key.

pnpm add keyover
Read the source

primary

serves first

Serving

spare

serves when it must

+7

Serving

App served
0
App failed
0
  1. Nothing sent yet. Send a request, then spend the primary's credit.

It happens to people who did everything right

Credit runs out at the worst hour, and the fix is waiting on someone to wake up, find a card and click.

I launched this at midnight prior to logging off and going to bed. I woke up and noticed my OpenAI account failed to fund. So we ran out of funds and it caused things to break for some of you.
MrRowTheBoat, on his own Show HN launchHacker News, 215 points
It seems like auto-recharge might be broken, and it took my site offline for more than an hour.
RyanW, in the thread Auto-recharge silently failedOpenAI developer forum. Support confirmed it and deployed a fix
Anthropic "credit balance is too low" (HTTP 400) blocks failover to the next credential
The title of a bug report on a popular proxy, since fixedAnthropic says it with a 400, and code that reads every 400 as a bad request strands a funded spare

One option on the client you already have

No gateway to run and no new client to learn. The pool is a fetch: your SDK keeps its retries, its streaming and its types.

import OpenAI from "openai"
import { createKeyPool, OPENAI } from "keyover"

const pool = createKeyPool({
  provider: OPENAI,
  keys: {
    primary: process.env.OPENAI_API_KEY,
    spare: process.env.OPENAI_API_KEY_SPARE,
  },
})

const openai = new OpenAI(pool.clientOptions)

const response = await openai.responses.create({ model: "gpt-6-luna", input: "Say hello." })
console.log(response.output_text)

A request moves only when the provider proves it never ran

A billing or key rejection arrives before any work starts, so sending the request again cannot run it twice. Every other answer goes back to your SDK untouched.

Moves to the next key

  • Out of credit429 insufficient_quota
  • Credit balance too low400 credit balance is too low
  • Spend limit reached429 organization_spend_limit_exceeded
  • A key the provider does not know401 invalid_api_key

Stays with your SDK

  • Rate limit429 rate_limit_exceeded

    A traffic control, and your SDK's to retry.

  • Server error5xx

    It may have run. A resend could run it twice.

  • Bad request400

    Another key cannot fix the input.

  • Organization on hold403

    A trust and safety decision. Never routed around.

The error you searched for, and what happens to it

Ten providers, each with its own way to say the money ran out. Every rule is backed by the provider's reference or a field report, and by a test.

Prove it before the night it matters

A fallback nobody has tested is a hope. One command sends a minimal request on each key, then runs a drill: a pool whose first key is invalid must still answer.

$ npx keyover check
openai  OPENAI_API_KEY        rejected: out of credit or over its limit (429)
openai  OPENAI_API_KEY_SPARE  serving
openai  drill  failover served: drill (invalid key) -> OPENAI_API_KEY, OPENAI_API_KEY -> OPENAI_API_KEY_SPARE
It names the environment variables, never their values, and exits 1 when a key cannot serve. Run it in CI or on a schedule.

Not a gateway, not a key rotator

Key pools and gateways exist, and some are very good. This one does a single narrow job inside the SDK you already use.

AspectA key rotatorA gatewaykeyover
What you changeWrap every call, or adopt its clientRoute all traffic through a proxy or a hosted serviceOne option on your existing client
When it switches keysOn most errors, rate limits includedOn the status codes or failures you configureOnly on a billing or key rejection
A rate limitJumps to another key, which is limit evasionOften falls backStays with your SDK's retry
A timeout or a 5xxResent on another key, and it may run twiceDepends on your configurationNever resent by the pool
A cap your provider assignedRouted aroundRouted around when the status matchesLeft alone unless you opt in
Where it runsIn your processA server or a service in the request pathIn your process, with no dependencies

When to use something else. If you need routing across providers, budgets per team, a dashboard or shared key health across a fleet, run a gateway such as LiteLLM, Portkey or Bifrost. They do far more than this does.

Questions

What is keyover?

keyover is an open-source TypeScript library that holds several API keys for one AI provider, in priority order, behind one fetch. When the provider refuses a request because the key's billing organization is out of credit, over its own spend limit, or the key is not accepted, the same request is sent again on the next key. It plugs into the OpenAI SDK, the Anthropic SDK and the Vercel AI SDK as their fetch option. It has no dependencies and is MIT licensed.

What happens when my OpenAI or Anthropic organization runs out of credits?

Without a fallback, every request fails until someone adds credit: OpenAI answers 429 insufficient_quota and Anthropic answers 400 with the message that your credit balance is too low. With the pool in place, the first rejected request is resent on your next key inside the same call, your code receives a normal response, and an event tells you which organization needs a top-up.

Does it rotate keys to get around rate limits?

No. A rate limit returns to your SDK untouched, and the SDK retries it as it always did. The pool also never moves a request for a safety hold, a region or IP restriction or a model your key cannot access, and by default it does not move one for a spending cap your provider assigned to your usage tier. It is built for billing resilience between organizations you are authorized to use, not for multiplying free tiers or limits.

Can a failover run my request twice?

The pool resends only a response the provider defines as a refusal given before any work started: a billing or authentication rejection. It adds no retry for a timeout, a 5xx, a dropped stream or any other failure that may already have run. Those go back to your SDK, which applies its own retry policy as before.

Does it work with streaming?

Yes. A billing or key rejection arrives as the HTTP response, before a stream starts, so the pool moves the request before any token is sent. A stream that has started is passed through and is never replayed.

What happens to the conversation when the organization changes?

Visible turns and tool results are portable, so a stateless request continues on the next key. OpenAI encrypted reasoning only decrypts in the organization that produced it: the pool detects that rejection and resends once without the reasoning items. Prompt caches start cold on the new organization. State stored at the provider, such as previous_response_id, files and vector stores, belongs to one organization and is not moved.

How does a key come back after I add credit?

A rejected key cools down, 30 seconds at first and up to 5 minutes. When the cooldown ends, a single request probes it while the others prefer the keys that serve. Once it answers 2xx it takes its priority back, with no restart. A cooling key is never refused locally: if every other key rejects, it is tried last, so a top-up works at once.

How is it different from LiteLLM, Portkey or OpenRouter?

Those are gateways: you send your traffic through a proxy or a hosted service, and you get routing across providers, budgets and dashboards. This is a small library inside your process that changes one option on the SDK client you already have, and it switches keys only for billing and key rejections. If you already run a gateway, you may not need it.

Which runtimes and SDKs does it support?

Any SDK that accepts a custom fetch: the official OpenAI and Anthropic SDKs, and the AI SDK providers. It uses only fetch, Request, Response and Headers, and it is tested on Node.js 20, 22 and 24, Bun and Deno.

I run several instances. Do they share key health?

No, and they do not need to. Health is in memory, per process. Each instance learns that a key is rejected with one fast extra round trip, then prefers the next key while the first cools down. There is no store to run.