# Set a daily spend limit on each API key your agents use

Updated November 17, 2026

On **OpenCheap**, every API key can carry its own spend limit: daily, weekly, monthly or lifetime, in UTC windows. Set it to `hard_stop` and the key's requests are refused with a `402` as soon as the next request no longer fits under the limit, counting requests still running, so a coding agent left running overnight stops at the amount you chose instead of draining your balance. An email goes out when spend crosses the alert share you pick (80 % by default). The limit counts every paid model the key calls, so it holds whichever model the agent switches to.

[Get API key](https://opencheap.si/start?onboarding=signin)

**4** windows: daily, weekly, monthly, lifetime

**Per key** and one for the whole account

**402** when the next request would not fit, until the window resets

## Cap an agent in three steps

1. **Give the agent its own key** One key per agent, project or customer, so each one's spend is counted and capped on its own.
2. **Set the limit** In the console under API keys, in the key's ⋯ menu › Budget & limits; by asking your agent over MCP; or with the Management API: `daily`, `weekly`, `monthly` and `lifetime`, at least one.
3. **Choose what happens at the limit** `hard_stop` refuses the key's paid requests with a 402 until the window resets; `alert_only` only emails. Both email once per limit and window at `alertPct` (80 by default, 0 for none).

## What happens at the limit

The check runs before the request reaches any model, so a refused request is never sent and never billed.

| Step | What OpenCheap does |
| --- | --- |
| Before the request is sent | It sets aside the most the request can cost: the prompt, plus max_tokens of output, at the price of the providers it may be sent to. Without max_tokens it sets aside the longest answer the model allows. |
| The check | Spend in the window so far, plus what requests still running have set aside, plus this request. If that is over any of the key's limits or the account's, the request is refused. |
| The refusal | HTTP `402` with `insufficient_balance`, the same code as an empty balance. The message names the budget, what was spent, when it resets and where to raise it. |
| When the answer ends | The request is charged what it really cost, and the rest of what was set aside is free again at once. |
| Until the window resets | Every paid request on that key gets the same 402. Free models still answer: they cost nothing. With alert_only, nothing is refused. |

what the agent gets back

```
HTTP/1.1 402 Payment Required

{
  "error": {
    "message": "this key's daily budget of $5.00 is reached ($5.02 spent today); it resets at 2026-11-18 00:00 UTC. Raise or remove it at https://app.opencheap.si/budgets",
    "type": "insufficient_balance",
    "code": "insufficient_balance"
  }
}
```

Because the worst case is checked first, a key usually stops a little before its limit, not after it. Set `max_tokens` on the agent's requests: without it a single request can need dollars of room on a model with a long output limit, and is refused while most of the limit is still unspent. When the room left is small, the message says the `max_tokens` that would still fit. A coding agent should treat this 402 as final and not retry it in a loop: it will be refused until the window resets or the limit is raised.

## Alerts, and where you see spend

| Where | What it shows |
| --- | --- |
| Email | One email per limit and window when spend crosses `alertPct` (80 % by default), to your contact address. Subject: “Budget alert: the key coding-agent is at 82 % of its daily limit”. It says whether requests will be refused at the limit and when the window resets. |
| Console banner | Every console page shows the alert until you dismiss it. |
| Spending limits page | Each budget with its spend this window as “$X of $Y”, and its status: OK, Alert or Stopped. |
| API keys page | Each key's spend over the last 30 days and its monthly limit. |
| Usage › Requests | Every request with its time, model, tokens and cost, filterable by key. |

Alerts are sent by email and shown in the console. To check from code, `GET /api/v1/budgets` returns each limit with its spend this window and when it resets.

## Which limit for which agent

Start from a normal day: the API keys page shows each key's spend over 30 days. Set the limit at two to three times a normal day, so a busy day passes and a runaway loop stops.

| Agent | Limit | At the limit | Alert at |
| --- | --- | --- | --- |
| Coding agent left running overnight | Daily, on its own key | hard_stop | 50 %, to hear about a loop early |
| Batch or eval job | Lifetime, on a new key for each run | hard_stop | 80 % |
| A new agent you are still testing | A small lifetime limit | hard_stop | 50 % |
| Agent in production that serves your users | Monthly, and a daily one to catch spikes | alert_only on the daily, hard_stop on the monthly | 80 % |
| The whole account | Monthly, as a backstop over every key | alert_only or hard_stop | 80 % |

## From code, or from your agent

terminal

```
# A daily cap of $5 and a monthly cap of $50 on one key, refusing requests at the limit.
# The Management API takes a management key (kl_rs_…, console › API keys › Agents), not the model key.
curl -s -X PUT https://app.opencheap.si/api/v1/keys/$KEY_ID/budget \
  -H "Authorization: Bearer $OPENCHEAP_MANAGEMENT_KEY" -H "Content-Type: application/json" \
  -d '{ "limits": { "daily": 5, "monthly": 50 }, "alertPct": 80, "mode": "hard_stop" }'

# → { "scope": "key", "limits": { "daily": 5, "weekly": null, "monthly": 50, "lifetime": null }, "status": "ok",
#     "windows": [ { "window": "daily", "limitUsd": 5, "spentUsd": 1.27, "resetsAt": "…T00:00:00Z" }, … ] }
```

over MCP, in Claude Code, Cursor or Codex

```
You: Make a key for my coding agent with a $5 daily limit that stops at the limit.
Agent: create_key → set_key_budget { daily: 5, mode: "hard_stop" }
       Done: key "coding-agent", $5 a day, resets 00:00 UTC.
```

Every endpoint, including the account budget and `GET /budgets` with each limit's spend this window, is in the [Management API docs](https://docs.opencheap.si/management-api); connecting an agent over MCP is in the [MCP docs](https://docs.opencheap.si/mcp).

## Spend limits elsewhere

From each one's own docs, as of November 14, 2026.

|   | Per key? | Windows | At the limit |
| --- | --- | --- | --- |
| OpenCheap | Yes, and per account | Daily, weekly, monthly, lifetime | 402 (hard_stop), or an email only (alert_only) |
| OpenAI | No: per organization and per project | Monthly | Hard limits return 429, not instantly; alerts only notify |
| Anthropic | No: per organization and per workspace | Monthly | Requests are refused until the month resets or the limit is raised |
| LiteLLM | Yes: `max_budget` on a virtual key | Any `budget_duration`, such as 1d or 30d | Requests rejected; you run the proxy and its Postgres database yourself |

## Questions, answered

### How do I set a daily spend limit on an API key?

On OpenCheap, give the key a budget: in the console under API keys, from your agent over MCP, or with PUT https://app.opencheap.si/api/v1/keys/{id}/budget and { "limits": { "daily": 5 }, "mode": "hard_stop" }. At the limit the key's requests are refused with a 402 until the day resets at 00:00 UTC.

### Can each key have its own limit?

Yes. Every key can carry its own daily, weekly, monthly and lifetime limits, and the whole account can have one too. Give each agent, project or customer its own key and its own cap.

### Does the limit block requests or only send an alert?

Your choice per budget: hard_stop refuses the key's requests with a 402 at a limit, alert_only never blocks. Both send one email per limit and window when spending crosses the alert share you set (80 % by default, 0 for no email).

### When do the limits reset?

In UTC windows: daily at 00:00 UTC, weekly on Monday, monthly on the first. A lifetime limit counts from when it was set and never resets.

### Does OpenAI or Anthropic have per-key spend limits?

Not per key, from their docs as of November 14, 2026: OpenAI sets monthly limits per organization and per project, and Anthropic monthly limits per organization and per workspace. A key on OpenCheap carries its own daily limit, across every model it calls.

### Does the limit cover every model?

Every paid one. A budget counts the key's spend at our price on every model it calls, Claude, GPT, Gemini and open models alike, so one cap covers an agent that switches models. Free models cost nothing, so they keep answering after a limit is reached, within their own daily cap. Time on an Instance is billed by the second and is not counted in budgets.

### Can a request go over the limit?

Rarely, and by little. Before a request is sent, the most it can cost is set aside and checked against what is left, so requests are refused before the limit, not after it. If the provider fails and a dearer one finishes the answer, that request is charged its real cost, which can end a little past the limit.

### What does my agent see when the limit is reached?

An HTTP 402 with error.code insufficient_balance, the same code as an empty balance. The message names the budget, what was spent, when it resets and where to raise it. Do not retry it until the window resets.

### How do I get alerted before an agent hits the cap?

Each budget has an alert share (alertPct): when spend in a window crosses it, OpenCheap emails your contact address once for that limit and window, and the console shows a banner. Set it lower, such as 50, to hear about a runaway agent earlier.

## More guides

- [Cheapest LLM API (Live Prices, Updated Daily)](https://opencheap.si/guides/cheapest-llm-api): Live prices per 1M tokens for popular models, routed to the cheapest healthy provider. One OpenAI-compatible key. Pay as you go; no monthly fee.
- [A cheaper DeepSeek API, with official prices side by side](https://opencheap.si/guides/cheapest-deepseek-api): Official DeepSeek API prices next to live OpenCheap rates for V4.1 Flash, V4 Pro and other DeepSeek models. One OpenAI-compatible key. Prices move; the tables are dated.
- [An LLM router that sends each request to the cheapest provider](https://opencheap.si/guides/cheapest-llm-router): OpenCheap routes each request to the cheapest healthy provider of your model, fails over before the first byte, and bills that provider's price.
- [One API key for all AI models](https://opencheap.si/guides/openai-compatible-api): One OpenCheap key calls Anthropic, Google, OpenAI, DeepSeek, Moonshot, Qwen and more through the OpenAI SDK: change the base URL and the key.
- [Pay for LLM API calls with USDC, without an account or an API key](https://opencheap.si/guides/pay-for-llm-api-with-usdc): An AI agent can pay OpenCheap for one completion in USDC on Base with x402: call with no key, read the 402 price, sign, and get the answer in the same request.
- [Connect Cursor, LiteLLM or the OpenAI SDK with the base URL](https://opencheap.si/guides/cursor-litellm-openai-sdk): Connect Cursor, LiteLLM and the OpenAI SDK to OpenCheap with a base URL, a key and a model id. Steps, env variables, code and common errors.
- [OpenCheap vs OpenRouter for cheapest pricing and failover](https://opencheap.si/guides/opencheap-vs-openrouter): OpenCheap routes to the cheapest provider by default; OpenRouter balances price, speed and uptime. Compare live prices, failover and fees.
- [A cheap Claude API, with official prices side by side](https://opencheap.si/guides/cheapest-claude-api): Anthropic's list prices next to live OpenCheap rates for Claude. One OpenAI-compatible key. Prices move; both tables are dated.
- [GPT API pricing, and the cheapest way to call it](https://opencheap.si/guides/cheapest-gpt-api): GPT API pricing per 1M tokens: OpenAI's list rates for GPT-6, GPT-5 and GPT-4 models next to live OpenCheap prices, on one OpenAI-compatible key.
- [The cheapest way to use Gemini through an API](https://opencheap.si/guides/cheapest-gemini-api): Gemini chat models on OpenCheap, with today's price per million input and output tokens from the same book as the pricing page.
- [The cheapest Qwen API, with official prices side by side](https://opencheap.si/guides/cheapest-qwen-api): Qwen API pricing per 1M tokens: Alibaba Cloud's list rates next to live OpenCheap prices for Qwen4 Max, Qwen3 Coder and more. One OpenAI-compatible key.
- [The cheapest Llama API, priced live](https://opencheap.si/guides/cheapest-llama-api): Llama API pricing per 1M tokens for Llama 4 Maverick, Scout, 3.3 70B and 3.1 8B, at the cheapest healthy provider. One OpenAI-compatible key.
- [The cheapest Kimi API, with official prices side by side](https://opencheap.si/guides/cheapest-kimi-api): Kimi API pricing per 1M tokens: Moonshot's list rates next to live OpenCheap prices for Kimi K3.1 Pro, K3 and K2.6. One OpenAI-compatible key.
- [Run Claude Code for less](https://opencheap.si/guides/claude-code-cheaper): Point Claude Code at OpenCheap and pick a model per task: Claude at the provider's price, or open models for a fraction, on one key with a spend limit.

---

Source: https://opencheap.si/guides/llm-api-spend-limits · All models: https://opencheap.si/models · Prices as JSON: https://api.opencheap.si/v1/prices · Index for agents: https://opencheap.si/llms.txt
