AI API cost alerts should fire before the monthly invoice surprises you. The right alert tells you that a feature is drifting, retries are rising, output is getting longer, or an agent is calling tools too many times.
If AI cost governance is the operating system and cost incident postmortems are the after-action review, cost alerts are the early warning system.
Why AI cost alerts need more than total spend
A single AI request can change cost because of model choice, input length, output length, cache behavior, retries, or tool calls. Total spend alone tells you too late.
| Metric | Why it matters |
|---|---|
| Per-request cost | Catches extreme inputs or outputs |
| Successful task cost | Separates useful spend from waste |
| Retry rate | Shows duplicate spend from failures |
| Output token share | Finds long-report or code generation drift |
| Agent tool calls | Detects loops and over-execution |
| Cache hit rate | Shows whether caching assumptions failed |
Five alert types
1. Daily budget alert
Every production AI feature needs a daily budget.
70% of daily budget → notify owner
100% of daily budget → downgrade or limit non-critical usage
This alert should include feature-level spend, not just provider-level spend.
2. Per-request cost alert
Trigger this when a single request exceeds the normal range.
Use P95 or P99 baselines for:
- document summarization;
- RAG answers;
- code generation;
- agent tasks;
- report generation.
3. Cost drift alert
Drift is slower than a spike but just as important.
Common causes:
- system prompt grew;
- chat history is not truncated;
- RAG chunks increased;
- responses became longer;
- routing upgrades too many requests.
4. Retry-rate alert
Retries multiply cost.
retry rate > 10% → investigate
retry rate > 20% → reduce retry or pause automation
Check whether the errors come from timeouts, JSON parsing failures, rate limits, tool argument errors, or duplicate submissions.
5. Agent loop alert
Agents need step and tool-call limits.
Monitor:
- model turns per task;
- tool calls per task;
- repeated calls to the same tool;
- human approval events;
- per-task budget usage.
An agent without a stop condition is a budget risk.
Logging fields for useful alerts
| Field | Example |
|---|---|
| feature | support_answer |
| model | claude-sonnet |
| user_tier | free, pro, internal |
| input_tokens | 3200 |
| output_tokens | 850 |
| estimated_cost | $0.011 |
| retry_count | 1 |
| tool_call_count | 3 |
| cache_hit | false |
| status | success, error, fallback |
Without these fields, alerts can tell you that spend increased, but not why.
Alert severity levels
| Level | Trigger | Action |
|---|---|---|
| Info | Cost reaches 50% of daily budget | Track trend |
| Warning | Cost reaches 70% | Notify owner |
| Critical | Cost reaches 100% | Downgrade or limit |
| Emergency | Spend grows and cannot be attributed | Pause risky feature |
Every alert should have an owner. Otherwise alerts become background noise.
Investigation checklist
When an alert fires, ask:
- Which feature triggered it?
- Is traffic actually higher?
- Did input tokens grow?
- Did output tokens grow?
- Did retry rate rise?
- Did agent tool calls increase?
- Did a prompt, route, or model change ship recently?
- Did a batch job repeat?
If you cannot identify the cause quickly, downgrade or pause the feature first, then investigate.
Before-launch checklist
- Feature-level daily budget exists.
- P95 per-request cost baseline exists.
- Retry threshold is defined.
- Agent step and tool-call limits exist.
- Batch jobs use idempotency keys.
- Every alert has an owner.
- Downgrade path is documented.
- Postmortem template exists.
FAQ
Do we need cost alerts from day one?
If the feature serves real users, yes. Start with daily budget and per-request cost alerts, even if they are simple.
Should thresholds be fixed dollars or percentages?
Use both. Fixed dollar thresholds protect budgets; percentages and P95/P99 thresholds detect abnormal requests.
What if alerts create too much noise?
Group by feature and owner. Reduce low-value info alerts, but keep critical budget, retry, and agent-loop alerts visible.
Final take
AI cost alerts make spending observable before it becomes a postmortem. Monitor feature-level budgets, per-request cost, retries, output growth, cache misses, and agent loops. Then connect every alert to an owner and a known action.