Last verified: July 21, 2026
Short path: Compare live rates on AI API pricing. Agent-specific depth: AI agent API bills.
Teams searching how to reduce LLM API costs usually start by switching vendors. That helps once — but sustained savings come from burning fewer tokens per successful task: routing, context discipline, retry control, and measuring what actually ships value to users.
This 12-point checklist applies to GPT, Claude, and Gemini through one LumeAPI OpenAI-compatible key (https://api.lumeapi.site/v1). Use it as a sprint backlog: export Usage, label expensive features, apply items 1–3 first.
LumeAPI is an independent gateway — not OpenAI, Anthropic, or Google.
Quick Answer — highest ROI moves
- Route by task — Flash/mini for 70–90% of calls (routing guide).
- Stop resending full chat history on every agent hop — summarize or window.
- Cap
max_tokensper API surface — streaming UIs over-generate without caps. - Retry with backoff — duplicate billable calls inflate spend (429 guide).
- Compare gateway catalog vs official realtime — then measure cost per completed task, not sticker $/1M (pricing comparison).
If you only do one thing: fix default model — running Opus/Pro/Sol on every hop is the most common production mistake.
The metric that matters: cost per successful task
cost_per_success = total_api_spend / completed_tasksA completed task is a user-visible outcome: ticket resolved, PR reviewed, document summarized — not “one HTTP 200.”
| Pattern | Why cost/success spikes |
|---|---|
| Agent loops | 5–15 model calls per user click |
| Retry storms | Same prompt billed 3× after 429 |
| Wrong default tier | Sol/Opus on classification |
| Context bloat | 50k input tokens × 10 hops |
Track weekly by feature flag. Optimize the worst ratio first.
12-point checklist (detailed)
| # | Action | Typical savings | How to implement |
|---|---|---|---|
| 1 | Default model = cheapest tier that passes evals | 40–70% | Set server-side defaults; block client override in prod |
| 2 | Escalate to Pro/Opus/Sol only on failure | 20–50% | Eval gate or explicit “premium” user tier |
| 3 | Summarize old turns vs full transcript | 10–40% | Rolling summary message every N turns |
| 4 | Prompt caching (official APIs where supported) | 10–90% input | Repeated system prompts; measure cache hit rate |
| 5 | Batch async jobs | ~50% on eligible work | Batch API guide |
| 6 | Deduplicate agent tool calls | 5–25% | Hash tool args; skip identical reads |
| 7 | Log cost per feature in Usage | Enables targeting | Tag requests with feature_id in app logs |
| 8 | Separate keys per service | Fewer 429 retries | Batch ETL vs realtime chat |
| 9 | Prompt caching patterns | Variable | Compare task cost, not input rate alone |
| 10 | Agent bills audit | High for agents | Cap hops; require tool justification |
| 11 | Cheapest LLM tier by scenario | Variable | Cross-provider picks |
| 12 | Shadow-test LumeAPI on 5–10% traffic | Validates gateway | Two-week A/B on cost/success |
Tiered routing in Python (one key)
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["LUMEAPI_KEY"],
base_url="https://api.lumeapi.site/v1",
)
MODELS = {
"bulk": "gemini-3-flash", # cheapest volume
"standard": "gpt-5.6-terra", # balanced GPT
"quality": "claude-sonnet-4-6",
"hard": "claude-opus-4-8", # escalation only
}
def complete(tier: str, messages: list, max_tokens: int = 800) -> str:
r = client.chat.completions.create(
model=MODELS[tier],
messages=messages,
max_tokens=max_tokens,
)
return r.choices[0].message.contentLog tier, model, input_tokens, output_tokens when the API returns usage.
Context trimming pattern
def trim_messages(messages: list, max_turns: int = 12) -> list:
system = [m for m in messages if m["role"] == "system"]
rest = [m for m in messages if m["role"] != "system"]
return system + rest[-max_turns:]For long sessions, replace dropped turns with a one-line summary message — not silence.
Monthly cost estimator (multi-model)
RATES = {
"gemini-3-flash": (0.15, 0.60),
"gpt-5.4-mini": (0.225, 1.35),
"gpt-5.6-terra": (0.75, 4.50),
"claude-sonnet-4-6": (1.80, 9.00),
}
def estimate(model: str, input_tokens: int, output_tokens: int) -> float:
inp, out = RATES[model]
return (input_tokens / 1e6) * inp + (output_tokens / 1e6) * outRates are LumeAPI catalog snapshots — verify models before budgeting. Deep GPT math: GPT pricing guide.
Gateway vs official: when each wins
| Factor | Official OpenAI / Anthropic / Google | LumeAPI gateway |
|---|---|---|
| Realtime GPT/Claude/Gemini list price | Baseline | Often ~70% below reference on catalog |
| Prompt caching | Strong when hit rate high | Depends on upstream |
| Batch API | ~50% off native batch | Use official batch for eligible jobs |
| Single SDK for 3 vendors | Multiple integrations | One OpenAI-compatible client |
| Enterprise commits | Negotiated | Compare effective $/task |
Shadow-test before migrating billing-critical workloads — cheap OpenAI guide.
Anti-patterns (do not optimize here first)
| Anti-pattern | Why it fails |
|---|---|
| Switch gateway without routing | Same token burn, smaller discount |
Crush max_tokens to 50 everywhere | Retries and user churn cost more |
| Remove logging to “save money” | You cannot target waste blind |
| Optimize tokenizer guesses | Use API usage fields |
30-minute audit workflow
- Export last 7 days from Usage.
- Group by
model— top 2 models = 80% of spend? - Map models to product features (logs).
- For #1 expensive feature: apply checklist items 1, 2, 3.
- Re-measure
cost_per_successafter one week.
Production checklist (copy to runbook)
- [ ] Document default model per API route
- [ ] Server-enforced
max_tokensceilings - [ ] Escalation rules written (not tribal knowledge)
- [ ] 429 retry policy with jitter and max attempts
- [ ] Weekly Usage vs forecast reconciliation
- [ ] Alert on daily spend > 2× trailing average
- [ ] Agent hop limit (e.g. max 8 model calls per task)
- [ ] Quarterly re-read AI API pricing
FAQ
What is the single biggest mistake?
Running Opus, Pro, or Sol on every hop in an agent. Default cheap; escalate on evidence.
Gateway vs official — which is cheaper?
Depends on workload. Gateways often win on standard realtime multi-model traffic. Official may win on batch + high cache hit. Measure cost/success.
How fast should we expect savings?
Routing + context trims often show within one billing cycle. Gateway migration needs shadow validation.
Does cheaper model always mean lower quality?
Not for narrow tasks. Classifiers and summarizers often pass evals on mini/Flash — cheapest LLM API.
How do 429 retries affect cost?
Each successful retry is a new billable call. Fix concurrency — Gemini 429, OpenAI 429.
Where do agents fit?
Start with agent bills guide — agents dominate surprise invoices.
Sources and verification
- AI API pricing, models, Usage — July 21, 2026.
- Related: reduce costs via routing, LLM pricing comparison.
Next steps
- Export Usage CSV for the last 7 days.
- Label your top 3 expensive features.
- Apply checklist items 1–3 this sprint.
- Re-run
cost_per_successnext Friday.