Running a multi-provider AI app means holding prepaid credit at half a dozen providers at once. And the fastest way to take the whole thing down is to let one of those balances quietly hit zero. So I built a Credit Balances page that shows what is left at every provider, keeps a history of every reading, and pushes an alert when a balance crosses a threshold.
The hard part turned out not to be the page. It was that no two providers agree on how, or even whether, they will tell you your balance. Some hand it over in a single authenticated GET. One hides it behind a different API with a different key. Two refuse to report a balance at all and will only tell you what you have spent. One offers nothing but a web console and a login screen.
Here's a summary of what I finally did.
#1 The provider just tells you
The happy path is a single endpoint that returns the remaining balance, authenticated with the very same API key you already use for chat completions - no extra credential, no second key to provision, no billing scope to configure.
DeepSeek and Kimi (Moonshot AI) both work this way.
#2 The provider tells you, but through a different door
xAI does expose a real prepaid balance, but not on the API you talk to for inference. It lives on a separate management API, which needs its own management key with billing read access, and the path is scoped to a team, so you also have to dig your Team ID out of the console URL and store it alongside the key.
The response has one more trap in it. It is denominated in USD cents and signed as a liability, so a $10 top-up comes back as -1000.
Mechanically this is still the same as #1, the number is real and authoritative. It just costs an extra credential and a sign flip.
#3 No balance, only spend
Anthropic and OpenAI publish no prepaid-balance endpoint at all. What they do publish is an organization-level admin cost API, which reports what you have spent over a date range.
So I invert the problem: the admin records their current balance once, by hand, and that manual entry becomes an anchor. Every subsequent fetch re-sums all spend from the anchor's timestamp to now and reports balance = anchor - spend.
Both vendors need an org-level Admin key rather than a normal inference key, and both report only finalized whole UTC days, so we sum the window [anchor_day, today) and deduct nothing until at least one full day has elapsed.
This gives an estimated balance. Drift accumulates from day-granular boundaries, and the fix is simply to re-record a fresh manual balance, which re-anchors everything.
#4 No API at all
Gemini (Google) exposes nothing usable: no balance endpoint, no admin cost API we can anchor against. The only way to know where you stand is to open the billing console and look.
References
- DeepSeek - https://api-docs.deepseek.com/api/get-user-balance/
- Kimi (Moonshot AI) - https://platform.kimi.ai/docs/api/balance
- xAI - https://docs.x.ai/developers/rest-api-reference/management/billing
- Anthropic - https://platform.claude.com/docs/en/api/admin/cost_report
- OpenAI - https://developers.openai.com/api/reference/resources/admin/subresources/organization/subresources/usage/methods/costs
- Google Gemini - https://aistudio.google.com/billing
