Why is my OpenAI bill so high?

The same question, and the same answers, apply to Anthropic. If multiple agents share one or two API keys, you have no way to know which agent is responsible when the bill jumps. The provider dashboard shows tokens by key, not by agent, customer, or feature. By the time the invoice arrives, the spike is three weeks old and nobody on the team remembers what shipped.

The bill rarely jumps for one big reason. It creeps for three small ones.

Across the teams we've talked to, the same three patterns account for most runaway-spend incidents. None of them produce an exception, none of them fail an existing alert, and none of them are visible in the provider's usage page.

The three usual suspects

  • Retry loops that carry full context. A new retry policy ships, a soft failure starts to recur, and each retry re-sends the full conversation history. One bad agent runs up two-thirds of the month's bill on its own.
  • Prompt creep. A handful of small additions to the system prompt over six weeks doubles the average input token count. No single change looked suspicious in code review; the cumulative effect is invisible until the invoice lands.
  • Ungated model swaps. An engineer changes claude-haiku to claude-opus for one agent because they were testing quality. The change ships. The cost-per-run for that agent jumps 12x and nobody notices for a week.

Cost-per-run, per agent, on a baseline that pages.

The smallest instrumentation that catches all three patterns is the same: a cost number per run, attributed to the agent that produced the run, with a rolling baseline that knows what normal looks like for each agent.

A real breakdown

spend · march 2026 · top customers by agent team rollup
Agent Customer Runs Cost Cost / run
support-triage acme-corp 12,408 $1,460 $0.118
research-agent (unattributed) 214 $409 $1.910
content-writer acme-corp 3,114 $967 $0.310
email-classifier acme-corp 18,672 $163 $0.009

The flagged row is a research-agent invocation running at 16x the cost-per-run of the other agents on the team, and missing its customer_id tag. That's a backfill job that started looping; the daily anomaly check finds it the morning it starts, not the first of next month.

The four things to instrument

  • Per-agent cost attribution. Every run records the agent, optional customer and feature tags, and provider-side token counts. Pricing is resolved server-side from a rate card so the SDK can't be wrong about your bill.
  • Cost-per-successful-run as the headline. Total cost over runs that finished cleanly. Loops and timeouts are excluded so the metric matches reality.
  • Anomaly detection on a 14-day baseline. Today's spend more than 2.5σ above the trailing mean fires the agent's alert route. Default threshold; configurable per team.
  • A spend guard on scheduled scripts. An opt-in check at the top of the script that refuses to start the next run once a spend rule trips. The alert tells you about last night's runaway; the guard stops tonight's.

Why the bill spikes when you resume a long agent session.

Chat APIs are stateless. Every turn of an agent session sends the whole conversation so far as input: the system prompt, every earlier message, every tool result. Turn forty pays for the thirty-nine turns before it, again.

Context growth, and the cache that expired

  • Input grows with every turn. A session that adds 2,000 tokens a turn sends 2,000 tokens on turn one and 80,000 on turn forty. The total input across the session grows with the square of its length, not in a straight line.
  • Caching hides it while the session is warm. Prompt caching bills the repeated prefix at a fraction of the input rate. On Anthropic a cache read costs 0.1x input on most models; on OpenAI, cached input is discounted by model.
  • Resuming after a break pays full price. Anthropic's default cache lives for 5 minutes from its last use (a 1-hour option costs more to write). OpenAI's retention depends on the model and your settings, from minutes to hours. Come back after lunch and the first turn bills the entire history as fresh input, and on Anthropic pays the cache-write premium on top.
  • Tools make it worse. Agents that paste large tool results (files, search pages, database rows) into the history carry that weight on every later turn.

The fixes are unglamorous: summarise or truncate old turns, keep tool output out of the history once it has been used, and put the stable part of the prompt first so it caches. How to claim the prompt-caching discount covers the last one in detail. Per-run cost makes the problem visible: a resumed session shows up as one run costing ten times its neighbours.

Which agent or team caused the spike? What you can still find out.

The invoice has arrived and the number is wrong. Before you instrument anything, check what the provider already recorded. How far that gets you depends on how you split your keys.

Looking back: what the provider can tell you

  • OpenAI. The usage dashboard filters by project, and its activity export groups by project, user, API key and model. The organisation Usage and Costs APIs return the same data programmatically with an admin key.
  • Anthropic. The Console's usage and cost pages break spend down by workspace. The Usage and Cost Admin API groups token usage by API key, workspace and model, and cost by workspace.
  • Find the day, then the model. Group by day to find when it started, then by model. A jump on one model on one day usually points at a deploy; check what shipped.

Where looking back runs out

If each team or agent has its own project, workspace or key, the provider report answers the question. If seven agents share one production key, it cannot: the provider never knew which agent made a request, so no export can recover it. The same goes for customers and features. That part needs attribution at the time of the run, tagging each run with its agent, customer and feature as it starts, so the next spike arrives already explained. Splitting keys per agent is a reasonable stopgap; it stops scaling once you want cost per customer.

Why is my OpenAI bill so high?
Usually not one big thing. The common causes are retry loops that resend the full conversation on every attempt, system prompts that have quietly grown, a model swapped to a pricier one for a single agent, and long sessions where every turn resends the whole history. None of them throw an error, so the first signal is the invoice. Cost per run, attributed to the agent that made it, shows which one moved.
Why is our Anthropic bill so high?
The same causes as OpenAI, plus one specific to prompt caching: cache writes cost more than plain input (1.25x for the default 5-minute cache, 2x for the 1-hour cache), so a cache that keeps expiring before it is read costs more than no cache at all. Check the ratio of cache reads to cache writes in your usage report before assuming caching is saving you money.
Why did my bill spike when I resumed a long agent session?
Each turn sends the whole conversation history again as input, so the cost of a turn grows with the length of the session. While the session is active, prompt caching bills most of that history at a fraction of the input rate. Leave it idle past the cache lifetime and the next turn pays full price on everything, and writes the cache again on top.
How do I find out which agent or team caused a spike after the invoice arrives?
Start with the provider's own reports. OpenAI's usage dashboard and Usage API break spend down by project, API key and model; Anthropic's Console and Usage and Cost API do the same by workspace, API key and model. If each team or agent has its own project, workspace or key, that answers it. If several agents share a key, the provider cannot separate them after the fact, and you need per-run attribution from now on.
My OpenAI dashboard shows tokens by API key. Why isn't that enough?
One API key usually serves multiple agents in the same environment. When the bill spikes, the dashboard can tell you "key A went up", but not which of the seven agents using key A caused it. Per-agent attribution requires tagging each run with the agent that produced it at the time the run starts.
What's the difference between cost and cost-per-successful-run?
Total cost over total runs is the wrong denominator. A loop that retries 50 times and fails inflates the run count and depresses the average, hiding the per-attempt cost. Cost over successful runs (status=success and quality threshold met) is the number finance can actually budget against.
How do I know which feature or customer is driving the spend?
Tag each run with a customer_id and a feature at run start. Aggregation is retroactive once tagged, so adding the tag today lets you slice every run going forward, and unattributed rows surface in the dashboard so you can find the cron or backfill job that forgot to tag.
Can I get alerted before the invoice arrives?
Yes. Anomaly detection runs a z-score on each agent against its trailing 14-day baseline. When today's spend exceeds 2.5 standard deviations above the trailing mean, the agent's alert route fires (Slack, PagerDuty, Microsoft Teams, email, or generic webhook). Most teams catch the spike on the same day it starts.
What about cached tokens? Are those priced separately?
Yes. Anthropic prompt-cache reads and OpenAI cached_tokens are priced from a separate row on the rate card. Cache creation is billed as regular input. The SDK never sends a cost number; pricing happens server-side from the rate card so you can't be wrong about your own bill.
Can I cap spend, not just get alerted about it?
Yes, with the opt-in spend guard. One call at the top of a scheduled script checks your rules (total spend, spend in a window, or run count, keyed by customer, agent, and function) against real cumulative spend before the run starts. Once a rule trips, or you hit pause in the dashboard, the next run refuses to start. Available on Team and Business plans.

How Agent Ping implements cost attribution.

Spend is the cost-attribution side of Agent Ping. The features page walks through the rate card model, anomaly detection, and per-customer cost rollups. The docs go one level deeper.

Spend features → Spend docs → Spend guard → Agent cost calculator → Track LLM cost per customer → What is AI agent observability? →