Usage limits are one of the most persistent complaints in the builder conversations we track. “the usage limit is just brutal… Like please give us some more cushion before we hit that weekly limit” (post). For people running several agents, the problem is visibility as much as the limit itself: “I run a team of Grok Bots and can only see the total, so I’ve no idea which one is the hungry one” (post). On the API side, the failure looks different but costs just as much: “We lost a week retrying a budget-capped key before anyone thought to check the dashboard” (post).
This guide covers the whole loop: why agents use so many tokens, how to see which agent is spending them, how to put a cap where the agent can’t get around it, what to do when the cap is hit, and how to use fewer tokens in the first place.
Scope: This guide covers token usage, plan limits, and API budgets. For limits on what an agent can buy with a card, see the guardrails guide’s hard limits on money. For per-run step, time, and spend caps, see Step 3 of our production reliability guide. For one key per agent and key expiry, see the security guide’s key hygiene step.
Why agents burn through limits
Every call re-sends the conversation
An agent doesn’t pay for its newest message alone. Claude Code’s docs explain that it “sends your full conversation with every request, and each time Claude uses tools it sends another request carrying that batch of tool results,” so “a one-line question in a session that has been open all day still draws usage for the whole conversation” (Claude Code: Manage costs). One builder’s summary of the same thing: “Most of your AI usage limit gets burned on re-reading old chat history, not actual work” (post).
AWS’s agent guidance calls this a compounding cost: “every token in context is paid on every subsequent invocation” (AWS Agentic AI Lens, AGENTCOST07-BP01).
More agents means more tokens
Splitting work across agents multiplies usage. Anthropic’s write-up of its Research feature says “agents typically use about 4× more tokens than chat interactions, and multi-agent systems use about 15× more tokens than chats.” It adds that multi-agent systems only make sense for “tasks where the value of the task is high enough to pay for the increased performance” (How we built our multi-agent research system). Claude Code’s docs give a similar figure for its own agent teams: “approximately 7x more tokens than standard sessions when teammates run in plan mode.”
Builders feel this directly. One post warned that turning an assistant “into a team of 6 bots” is “the fastest way to BURN YOUR WEEKLY USAGE LIMIT” (post).
Idle agents still spend
An agent that looks idle may still be working. Claude Code’s docs list the usual causes: scheduled tasks that fire “on its interval even while the session is idle, sending your full context each time,” the first message after a break that “misses the cache and reprocesses your full context,” and teammates that keep “consuming tokens until it exits.” Background work like this (in Claude Code or any other agent tool) may explain posts like “30% to 0% with nothing running!” (post).
Alerts don’t stop anything
Many setups have alerts and assume they have limits. OpenAI’s docs draw the line clearly: a spend alert “sends a notification; API traffic continues,” while a hard spend limit makes affected requests “return a 429 error” (OpenAI spend limits). AWS’s guidance agrees: enforce budgets “as pre-invocation checks, not alerts after the fact.”
Step 1: Figure out which limit you hit
“Out of usage” can mean four different things, and each one has a different fix:
| What you hit | What it looks like | What fixes it |
|---|---|---|
| Plan usage window (subscription assistants) | Claude Code: “You’ve hit your session limit” or “You’ve hit your weekly limit” | Wait for the reset, use fewer tokens, or turn on paid overage (Step 10) |
| A spend cap you set | OpenAI: 429 with project_spend_limit_exceeded. OpenRouter: 402 for credit limits or 403 for budget limits. LiteLLM: budget_exceeded | Raise the cap or wait for the window to reset. Retrying won’t help |
| Rate limit (requests or tokens per minute) | 429 with a Retry-After header or a rate-limit error type | Back off and retry, or spread the load |
| Account balance | OpenRouter: 402. OpenAI: credit_balance_exhausted | Add credits |
Sources for the error codes: Claude Code costs, OpenAI spend limits, OpenRouter limits, and LiteLLM budgets, all checked Oct 18, 2026.
Two details matter here. First, Claude Code’s session and weekly limits are “shared across all models,” so switching models with /model won’t restore access. A model-specific message like “You’ve hit your Opus limit” is different, and switching to another model family does keep you working. Second, a 429 can mean either “slow down” or “you’re out of budget.” Read the error code before you decide to retry.
For subscription assistants other than Claude Code, Grok Bot included, check your plan’s own usage page for how its windows work. We only describe limits we’ve checked in official docs.
Step 2: Measure cost per agent and per task
You can’t fix “which one is the hungry one” from a single total. Give every agent, routine, and scheduled job its own label, and track spend under that label.
- Claude Code subscribers: on Pro, Max, Team, or Enterprise plans,
/usageshows “recent usage attributed to skills, subagents, plugins, and individual MCP servers, each shown as a percentage of the total,” plus rows for the heaviest/loopand scheduled tasks. It also flags behaviors like long context or cache misses “when one accounts for 10% or more of recent usage.” The figures come from local session history, so usage from other devices isn’t included. - Helicone: group requests into sessions with
Helicone-Session-Idto “show the true cost of user interactions,” and tag them with custom properties (Helicone-Property-*) to split cost by feature or environment (Helicone cost tracking). One property per agent answers the “hungry one” question. - Langfuse: records usage and cost for every LLM generation and lets you build dashboards of “cost across models, tags, or users” and set alerts when spend crosses a threshold (Langfuse cost tracking). It can’t infer cost for reasoning models unless you send token counts, so pass them through.
- LiteLLM: if each agent has its own virtual key, spend is tracked per key automatically.
Measure cost per finished task, not cost per call. A cheap call that loops five times can cost more than one expensive call that finishes.
Step 3: Put a hard cap on each agent, outside the agent
A budget written in the prompt is a request, not a limit. AWS’s guidance is to “implement cost controls outside the agent’s control loop” so agents can’t bypass them “through prompt manipulation.” The place to enforce a cap is the gateway, the provider account, or the key.
Gateway caps (per agent). Route every agent through a gateway and give each agent its own key with a budget. In LiteLLM, a key with max_budget set stops working once it’s spent: “After the key crosses it’s max_budget, requests fail.” You can stack windows on the same key. LiteLLM’s docs suggest this so “a single heavy session doesn’t exhaust the whole month”:
curl 'http://0.0.0.0:4000/key/generate' \
--header 'Authorization: Bearer <your-master-key>' \
--header 'Content-Type: application/json' \
--data-raw '{
"key_alias": "research-agent",
"budget_limits": [
{"budget_duration": "24h", "max_budget": 10},
{"budget_duration": "30d", "max_budget": 100}
]
}'
The dollar amounts are LiteLLM’s own example, not a recommendation. LiteLLM’s Agent Gateway can also cap single sessions with max_iterations and max_budget_per_session, which return a 429 when exceeded (LiteLLM budgets and rate limits).
One catch: LiteLLM budgets need a database. Without one, the docs warn that the global budget “fails open” and “requests keep being served past the limit.” If a budget is your safety net, run LiteLLM with Postgres and check the startup logs.
Helicone can cap by cost instead of request count. Its Helicone-RateLimit-Policy header takes a quota in cents with u=cents, scoped per user or per custom property, and returns a 429 once it’s reached (Helicone custom rate limits). Point the segment at an agent property and each agent gets its own spend ceiling.
Provider caps (backstop). Set these too, in case something bypasses the gateway:
- OpenAI: set a monthly spend limit on the project and turn on “Enforce a hard limit.” Without that toggle, the limit doesn’t block traffic.
- OpenRouter: set a credit limit on each API key, and check
GET /api/v1/keyforlimit_remaining. OpenRouter suggests watchingeffective_budget.remaining_usdbefore a long task “to avoid hitting the cap partway through.”
Claude Code headless runs. For claude -p jobs, --max-budget-usd stops the run “once estimated spend on API calls reaches this amount,” and subagent spend counts toward it (Claude Code CLI reference).
Step 4: Treat a budget error as a stop, not a retry
When a spend cap trips, the agent’s retry logic is usually what wastes the most time. A spend-cap error won’t clear on its own. OpenRouter’s docs say that before a budget’s reset time, “Retrying before it will fail the same way.” In OpenAI’s case, traffic resumes only when someone raises or removes the limit, or “the limit resets with the next monthly cycle.” A builder describing gateway setups put it simply: “Not every 429 is temporary: a spend-cap 429 won’t clear however often you retry” (post).
In your error handling:
- Read the code, not just the status. Look for
project_spend_limit_exceeded,budget_exceeded, OpenRouter’slimit_source, or a403budget error. Only rate-limit429s and transient5xxerrors are worth retrying. - On a budget error, stop the run and send a short message to a person: which agent, which cap, and when it resets.
- Don’t fall back to another key automatically. That turns a cap into a suggestion.
Our production guide covers general retry rules, such as backoff and retrying in only one layer.
Step 5: Stop cleanly before the limit, not at it
Caps aren’t exact. OpenAI says “recorded spend can slightly exceed the configured amount.” Claude Code’s docs on --max-budget-usd say “Spend can pass the cap, so leave headroom.” LiteLLM handles parallel requests by reserving each request’s estimated maximum cost first, and warns that turning that off “can allow concurrent requests to exceed a configured budget.”
What hurts more than a small overshoot is an agent killed halfway through a task. One builder built a fix for exactly that: “When your 5h/weekly limit drops below 5%, every running agent (subagents too) gets told to finish the step, write a handoff, and stop cleanly” (post). We haven’t tested that tool, but the pattern works anywhere:
- Set a soft threshold below the hard cap, such as a warning at a share of the budget you choose.
- At the soft threshold, finish the current step and write a handoff file: what’s done, what’s next, and where the files are.
- Resume from the handoff after the reset, rather than starting the task over. Our production guide covers saving state.
Step 6: Send routine work to cheaper models
The most common fix builders describe is matching the model to the job. One post: “The most expensive model was doing everything, even the routine checks… The cheap model runs status checks and scheduled jobs. The strong model plans and reviews” (post). The author says the setup isn’t live yet. Their line: “You don’t send your most senior officer to do a headcount.”
Official docs say the same:
- Claude Code’s docs recommend Sonnet for most coding tasks, reserving Opus “for complex architectural decisions,” and setting
model: haiku“for simple subagent tasks.” They also warn that “a switch to Opus also applies to the subagents that inherit your session’s model,” so pick subagent models on purpose. - Lower the thinking effort for simple tasks. Claude Code’s docs note that “thinking tokens are billed as output tokens.”
- At the gateway, LiteLLM supports per-model budgets and lets budget-exhausted keys keep using models you’ve marked as zero-cost, such as a self-hosted model. Helicone’s gateway can route to the cheapest available provider for a model.
Before you move a task to a cheaper model, test it on real examples. A cheaper model that fails and retries costs more than the expensive one did. Our production guide covers building a small eval set.
Step 7: Shrink what every call re-reads
Because each call re-sends the context, reducing the context saves tokens on every call that follows. From Claude Code’s docs:
- Clear between unrelated tasks with
/clear. “Stale context wastes tokens on every subsequent message.” Compacting is itself “a large request,” so clear when you don’t need continuity. - Keep instruction files short.
CLAUDE.mdloads at session start whether it’s relevant or not. The docs suggest moving workflow-specific instructions into skills, which load only when used, and to “aim to keep CLAUDE.md under 200 lines.” - Turn off unused MCP servers, and prefer CLI tools such as
ghwhere they do the same job, because they “don’t add any per-tool listing.” - Filter tool output before the model sees it. The docs’ example uses a hook to grep a log for errors instead of letting the agent read the whole file, “reducing context from tens of thousands of tokens to hundreds.”
- Push verbose work to subagents so long test output stays out of the main conversation. The subagent’s tokens still count, so give it a smaller model.
For agents with long-term memory, retrieving everything on every turn has the same effect. See the memory guide’s step on retrieving narrowly.
Step 8: Use caching on purpose
There are two kinds of caching, and they save tokens in different ways:
- Provider prompt caching reuses an unchanged prefix of the prompt. Claude Code’s docs say the cache lifetime is “an hour on a subscription and drops to five minutes once you’re drawing on usage credits,” and five minutes by default on an API key. The first message after a longer break reprocesses the full context. Keep the system prompt and tool definitions stable at the start of the prompt so the prefix can be reused. In Claude Code,
/usageshows the share of input tokens served from cache and the likely cause of the last miss. - Response caching at the gateway returns a stored answer for a repeated request. Helicone turns this on with a
Helicone-Cache-Enabledheader and suggests it for FAQ answers, static content, and dev and test environments. Be careful with agents: one builder noted that a semantic cache, which answers similar prompts, “is risky for agent traffic” (post).
Step 9: Turn off idle and background spending
List everything that runs when you’re not watching, then cut what doesn’t need to run:
- Scheduled tasks and loops. Each run re-sends its context. Run them less often, give them a cheap model, and have them exit early when nothing has changed. One builder’s rule list includes: “Routines stay silent if nothing has changed” (post).
- Agent teammates and background subagents. Claude Code’s docs say to “shut down teammates when their work is done.”
- Duplicate harnesses. Two tools watching the same inbox or repo both pay for it.
Then check Step 2’s per-agent numbers again a week later to see what changed.
Step 10: Decide on overage and subscriptions before you need them
Overage. Some plans let you keep working past the limit by paying as you go. With Claude’s usage credits, once a five-hour or weekly limit is used up, “your requests switch to pay-as-you-go pricing” at standard API rates. The settings include a monthly spend limit, and also an option to “Set to unlimited” (Claude Help Center: usage credits, checked Oct 18, 2026). If you turn on overage, set a monthly cap at the same time. Otherwise a hard stop becomes an open-ended bill.
Stacked subscriptions. Some builders spread work across many tools to stretch free allowances. One described it this way: “i’m a token scavenger.. i use a bunch of different harnesses chasing wherever the free tokens are,” and found it “annoying to maintain that many different harness setups” (post). If you pay per token, one gateway in front of every provider (LiteLLM or OpenRouter) gives you one key per agent, one place to see spend, and one place to set caps. LiteLLM’s gateway is MIT-licensed and free to self-host (litellm.ai, checked Oct 18, 2026). Helicone’s Hobby plan includes 10,000 free requests a month (Helicone pricing, checked Oct 18, 2026). Check the current pricing pages before you commit, because plans change.
If an agent can also spend money outside the model API, such as on purchases or cloud resources, use the card and approval controls in the guardrails guide.
Checklist
| Check | Done when |
|---|---|
| Limit types | You can tell a plan window, a spend cap, a rate limit, and an empty balance apart from the error alone |
| Per-agent spend | Every agent and scheduled job has its own key, tag, or session label |
| Cost per task | You know what a finished task costs, not just a call |
| Hard caps | A per-agent cap at the gateway or key, plus a provider hard limit as backstop |
| Fail-closed budgets | LiteLLM (if used) runs with a database; OpenAI’s “Enforce a hard limit” is on |
| Error handling | Budget errors stop the run and alert a person; only rate limits retry |
| Clean stop | A soft threshold below the cap triggers a handoff file |
| Model routing | Routine steps run on a cheaper model that passed your evals |
| Context size | Short instruction files, unused MCP servers off, tool output filtered |
| Caching | Stable prompt prefix; response cache only where answers don’t change |
| Background work | Every scheduled job is listed, cheap, and exits early when idle |
| Overage | Paid overage has a monthly cap, or is off |
FAQ
Why does my AI agent hit its usage limit so fast? Each call re-sends the whole conversation and tool results, so long sessions get more expensive with every message. Multi-agent setups multiply that: Anthropic measured about 15 times the tokens of a chat. Scheduled tasks and cache misses after breaks add usage even when you aren’t actively working.
Do spend alerts stop API charges? No. On OpenAI, a spend alert only sends a notification and traffic continues. To stop requests, set a hard spend limit on the project or organization, or cap the agent’s key at a gateway.
How do I set a hard spending limit for one AI agent? Give the agent its own API key and put a budget on that key, either at a gateway like LiteLLM or as a per-key credit limit on OpenRouter. Keep a provider-level hard limit as a backstop. Don’t rely on a budget written in the prompt.
Should my agent retry when it gets a 429 error? Only if it’s a rate limit. A 429 caused by a spend cap, such as OpenAI’s project_spend_limit_exceeded or a LiteLLM budget error, won’t clear until someone raises the cap or the window resets. Check the error code, stop the run, and alert a person.
How do I find which agent is using the most tokens? Label every agent and scheduled job separately: its own gateway key, a custom property in Helicone, or tags in Langfuse. Then compare cost per finished task. In Claude Code, the /usage breakdown attributes usage to subagents, skills, MCP servers, and scheduled tasks.
Get the next guide in your inbox
We’re tracking usage limits, token costs, and the gateways and tools that claim to control them, for people building AI agents and Grok Bot setups. Subscribe to the newsletter for practical guides and directory picks.