API Key Spend Limit: A Budget Cap for AI Agents

· 0x.cloud Team

API Key Spend Limit: A Budget Cap for AI Agents

An API key spend limit is a monthly dollar cap: past it, the key cannot buy anything with your balance. Give an agent a $20 cap and, even with $500 on the balance, its key cannot create a server or add an add-on that would push the month past $20. On 0x.cloud the API key spend limit is set when you create the key and covers servers and add-ons bought through that key.

It is your main safety net when servers are ordered by an AI agent (Claude Code, Codex, Cursor, ChatGPT) or an n8n workflow rather than a person. An agent's mistake turns into a rejected request instead of a charge for hundreds of dollars.

How the Spend Cap Works

Aspect Behavior
Where it is set on each API key separately
Unit US dollars per calendar month
What counts everything charged by the key's requests (servers, snapshots, backups, plan upgrades), plus hourly billing and renewals of servers the key created, minus refunds on delete
At the cap the paid request is rejected with 402, nothing is charged or changed
Running servers are not shut down by the cap
Account balance shared; the cap only limits one key's share

The cap does not add money or reserve it. With $5 on the balance and a $20 cap, the key can spend at most $5. The lower of the two wins.

One catch. The cap blocks new purchases but does not shut down servers that already exist. An hourly server the agent forgot to delete keeps billing, and the key's spending can go past the cap. Create temporary servers with a timer: the ttl_hours field (1 to 720 hours) deletes the server on its own and returns the remainder to your balance.

Spend Cap vs Key Scopes

The cap limits how much a key spends; scopes limit what it can do:

  • read (servers.read, billing.read): plans, balance, server list; spends nothing;
  • create (servers.create): creates servers and add-ons; this is where the cap applies;
  • delete (servers.delete): deletes servers.

A read-only key spends nothing and needs no cap. Note that a new key gets servers.* by default, which includes both create and delete: trim it for an agent. More in API key permissions.

How to Set an API Key Spend Limit

  1. Sign in to the 0x.cloud dashboard and open the API keys section.
  2. Create a key with a clear name: claude-code-laptop, n8n-prod.
  3. Pick scopes. For an agent that creates servers: read and create (servers.read, servers.create, billing.read), no delete.
  4. Enter a monthly spend cap, for example 20.
  5. Save the key and copy it straight into an environment variable or your MCP client settings.

To change the cap later, edit the key's settings in the dashboard. No need to issue a new key. The key cannot raise its own cap: over the API it can only change its name.

To see how much a key has spent, call this with the key itself:

# key scopes, spend rule, spent and remaining this month
curl https://0x.cloud/v1/account/key -H "Authorization: Bearer $OX_API_KEY"

How to Pick a Budget Cap

Size it to the job, not "just in case". Reference points from plan prices:

Key for What it does Cap
Experimental agent spins up s1-1 or s1-2 hourly for tests $5–10
Coding agent keeps one s2-4 ($15.99/month) $20
n8n or CI creates servers for jobs and deletes them monthly hours + 20% buffer
Agent running several bots 2–3 s1-2 servers ($7.99 each) $25–30

CI example: an s4-8 server for 3 hours a day, 22 workdays. That is 66 hours at $0.219105, about $14.46 a month. A $20 cap covers the month with room to spare, as long as each server is deleted after the build.

A $1,000 cap "so it never gets in the way" does nothing against a $500 mistake. Start small and raise it once you see real usage.

Pair the Cap With dry_run and Approval

The cap works best alongside two rules:

  1. The agent first checks the exact price with dry_run: the service returns the amount and creates nothing.
  2. The agent shows you the price and waits for your yes.

Put the rule into the agent's instructions, for example CLAUDE.md or AGENTS.md:

Prompt for an AI agent

My 0x.cloud key has a monthly spend cap. Before creating any server, run dry_run, show me the hourly and monthly price, and wait for my approval. If a request is rejected because of the cap (error 402), do not try to work around it with another plan or term: tell me the amount and the reason, and if the spend is really needed, ask me for a one-time approval.

One-Time Approval Above the Cap

If the agent really needs to spend more, it does not have to ask you to change the cap. A cap rejection comes with an approval request, and you approve or deny it in the dashboard. An approved request covers one paid action up to the stated amount within 24 hours; after that the cap works as before.

The full checklist (separate key, minimal scopes, cap, approval) is in how to limit an AI agent. For how agents use the cloud end to end, see 0x.cloud for AI agents. If your agent needs its own always-on server, start with s2-4 ($15.99/month; 2 vCPU and 4 GB RAM fit a coding agent with Docker): see VPS for AI agents.

Common Issues

Error 402 key_spend_limit_reached with money on the balance. The key hit its monthly cap. The response includes limit_usd, spent_usd, remaining_usd, required_usd and resets_at (when the counter resets). Retrying will not help: raise the cap in the dashboard, delete servers you do not need (refunds lower the key's spending), or approve a one-time request.

Error 403 key_spend_forbidden. The key is set to "cannot spend". That is right for a price-check key; to create servers, issue a key with a cap.

The agent tries a different plan after a rejection. That is model behavior, not a cap bug, and the cap still holds. Add a "do not work around it" rule, as in the prompt above.

The cap does not seem to apply. Make sure the agent uses this key and not your personal key without a cap. One key per agent.

The balance ran out before the cap. A cap adds no money. Top up, or servers get paused: see what happens when your balance runs out.

FAQ

What is an API key spend limit? A dollar amount a key can spend per month. Past that amount, requests made with the key cannot buy anything, even if your balance has more money.

Is the limit set per account or per key? Per key. Every key has its own cap, so your agent, n8n and your scripts can each get a different budget.

What happens when an agent hits the cap? The paid request is rejected with 402 key_spend_limit_reached and nothing is charged. The agent sees what is left and when the cap resets, and can ask you for a one-time approval.

Can an agent raise its own cap? No. Only the owner can change a key's scopes and cap, in the dashboard. A request signed by the key itself can only rename it.

Does this cap limit my OpenAI, Anthropic or Gemini spending? No. The 0x.cloud spend cap covers 0x.cloud servers and add-ons only. Model API keys and their spend limits are set separately in your model provider's console.