Skip to content
AI

AI API Cost Incident Postmortem: Stop the Bill Spike Before It Spreads

AI

AI Cost Calculator

5 min read

An AI API cost incident rarely happens in one moment. The bill spike is usually the visible symptom of earlier signals: retry rate increased, context grew, agents started calling tools repeatedly, batch jobs ran twice, or a model switch shipped without new limits.

The real problem is not that the bill grew. The real problem is not knowing which feature caused it, why it happened, how to stop it, and how to prevent the same pattern from returning.

What counts as an AI API cost incident?

Not every cost increase is an incident. Growth, more customers, or a planned quality upgrade can raise the bill in a healthy way.

A cost incident usually has these traits:

SignalWhat it means
Unexplained growthNo product launch or usage growth explains the bill
Unit cost changedCost per successful task went up
Budget boundary crossedDaily or monthly budget is exceeded
No clear ownerNobody knows which feature caused the increase

If total spend is high but every feature behaves as planned, you have a budgeting problem. If spend is high and unexplained, you have an incident.

Step 1: stop the bleeding first

Do not start with a long postmortem while the bill is still climbing.

Use this order:

  1. Pause low-value batch jobs.
  2. Downgrade non-critical features.
  3. Pause autonomous agent execution.
  4. Cap output tokens.
  5. Reduce retry limits.
  6. Disable long-context mode.
  7. Add temporary user or feature quotas.

The goal is to flatten the cost curve before you investigate.

Step 2: rebuild the timeline

Do not start by asking who made the mistake. Start with what changed.

TimeEventEvidence
T-7 daysPrompt became longerGit diff / prompt version
T-5 daysMore RAG chunks were addedRelease note
T-3 daysAgent tools were enabledConfig change
T-1 dayRetry rate increasedRequest logs
TBudget alert firedBilling dashboard

Without a timeline, teams blame the last visible change, not the root cause.

Step 3: attribute the cost

At minimum, break the incident down by:

DimensionQuestion
featureWhich feature got expensive?
modelWhich model drove spend?
user_tierFree, paid, internal, or batch?
input_tokensDid context grow?
output_tokensDid responses get longer?
retry_countDid failures repeat?
tool_callsDid agents loop?
cache_hitDid caching stop working?
statusWere failures spending money?

The goal is not to find “the expensive model.” The goal is to find the expensive path.

Common cause 1: context slowly grew

Context creep is quiet. It happens when:

  • Chat history is not truncated.
  • More RAG chunks are inserted.
  • System prompts keep expanding.
  • Tool outputs return full JSON instead of summaries.
  • Irrelevant context is sent by default.

Compare average input tokens and P90 input tokens before and after the incident.

Common cause 2: output length was uncapped

Writing, reporting, code generation, and summarization features often overspend through output tokens.

Controls:

  • Set max output tokens.
  • Default to concise answers.
  • Require confirmation for long reports.
  • Use structured output where possible.
  • Add cooldowns for regenerate buttons.

Common cause 3: retry rate spiked

Retries multiply cost directly.

real cost = normal cost × (1 + retry rate)

Check whether retries came from:

  • Upstream timeouts
  • JSON parsing failures
  • Tool argument errors
  • Missing idempotency
  • User-triggered repeated submissions

Common cause 4: agents looped through tools

Agent systems need hard limits.

Minimum controls:

  • Maximum steps
  • Maximum tool calls
  • Per-task budget
  • Human approval for write actions
  • Retry limit after tool failure

An agent without stop conditions is not automation. It is an open-ended budget risk.

Common cause 5: batch jobs repeated

Batch jobs cause incidents when:

  • Cron jobs run twice.
  • Queue messages are not acknowledged.
  • Failed jobs replay the full batch.
  • Multiple workers process the same item.
  • The same document is summarized repeatedly.

This is often an application workflow problem, not a model pricing problem.

Cost incident postmortem template

## Incident summary
- Time:
- Impact:
- Estimated extra cost:
- Current status:

## Timeline
- T-7:
- T-3:
- T:

## Cost attribution
- Main feature:
- Main model:
- Input/output token change:
- Retry rate:
- Agent tool calls:

## Root cause
- Direct cause:
- Systemic cause:

## Actions taken
- Paused:
- Downgraded:
- Limited:

## Prevention
- Daily budget alert:
- Per-request cost cap:
- Retry limit:
- Launch checklist update:

Prevention checklist

  • Every AI feature has a feature-level budget.
  • Requests log input and output tokens.
  • Retries are capped.
  • Agents have max steps.
  • Batch jobs use idempotency keys.
  • Daily and weekly budget alerts exist.
  • Prompt changes are versioned.
  • Model switches trigger new budget estimates.
  • First-week post-launch review is scheduled.

FAQ

What should we do first when the bill spikes?

Stop the growth first. Pause low-value jobs, cap outputs, reduce retries, and pause autonomous agent execution before running a full postmortem.

Is a cost incident always caused by an expensive model?

No. The more common causes are long context, long output, retry loops, cache misses, agent loops, or repeated batch jobs.

Can we do a postmortem without perfect logs?

Yes, but it is slower. Use billing data, release history, queue logs, prompt versions, and traffic changes to reconstruct the timeline. Then add request-level cost logs so the next incident is easier.

Final take

An AI API cost incident is an observability problem as much as a finance problem. If your team can stop the spike, rebuild the timeline, attribute cost by feature, and turn the lesson into launch controls, the incident becomes part of your cost governance system.

Recommended