When estimating the cost of LLM API, you cannot just look at the unit price of the model. True cost is also affected by input history, output length, failure retries, tool loops, and model routing. This article does not write fixed prices to avoid misleading after model price adjustments.
Check before you start
First collect a batch of real business samples, including at least:
- General short questions and answers.
- Multiple rounds of conversations with history.
- Long documents or code input.
- Tool call or Agent task.
- Failures, timeouts, and retry requests.
The model price, magnification and available range are subject to the real-time display on the AIFast console and price page.
When the current input price and output price have been obtained, you can open Token cost calculatorFill in the real Token, number of tasks, and failure retry ratio to first obtain a recalculated batch cost baseline.
Configuration steps
1. Record the complete usage of a request
If the API returns usage, save at least:
{
"model": "YOUR_MODEL_ID",
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0,
"retry_count": 0,
"status": "success"
}
The above uses Chat Completions common prompt_tokens、completion_tokens and total_tokens. The Responses API or other compatible APIs may use different field names, which must be parsed according to the actual response. Account reconciliation is based on console records, and application logs are used to analyze request structure and trends.
2. Use a repeatable cost formula
cost per task
= Enter usage × Enter unit price
+ Output usage × Output unit price
+ Retry request cost
+ Additional request costs incurred by tool loops
Don’t just count the one time you finally succeeded. If content has been previously generated but the client times out, the related request may still generate usage.
3. Find the most common hidden costs
| Hidden costs | Check method |
|---|---|
| Send the entire history repeatedly every round | Record whether input_tokens continues to grow rapidly in each round |
| There is no length limit on the output | Check if the task requires explicit stopping conditions or output structures |
| Retry infinitely after failure | Record retry_count and final status |
| Agent tool loop | Record the number of model requests for each tool step |
| All tasks use the same high-cost model | Statistics of quality and cost according to task difficulty |
| Regenerate after streaming interruption | Set idempotent status for tasks and retain completed status |
4. Routing model by task
First create a small evaluation set by task type, and then decide on the route:
- Classification, extraction, format conversion: Prioritize evaluation of low-latency, low-cost models.
- Complex code, long reasoning: focus on comparing success rate and number of reworks.
- Images, videos, retrieval: separate statistics based on actual input and output units, cannot be directly applied to the text Token formula.
- Agent: Count the total number of calls required for a complete task to succeed, rather than just looking at a single price.
A model that is cheap but often reworked may cost more for a complete job; a model that is more expensive but is done once and for all may also be better suited for critical processes.
5. Set up budget protection
It is recommended to set both:
- The maximum output length of a single task.
- The number of requests per minute for a single user.
- Maximum number of tool cycles per task.
- Single day or single project budget reminder.
- Abnormal retry and usage sudden increase alarms.
FAQ
Why console charges and local estimates don't exactly match
Possible reasons include price multiplier changes, caching or inference usage breakdown, streaming interruptions, retries not being accounted for, missing local fields, or asynchronous accounting delays. Financial reconciliation should be based on the console bill.
Does the shorter the input, the cheaper it must be?
Usually the amount of input required can be reduced without sacrificing information necessary for the task. Excessive compression causes the model to repeatedly query or output errors, which may increase the total number of calls. The total cost of "completing a business task" should be compared.
How to judge whether you should change the model
Also compare success rates, manual rework time, delays, and complete task costs. Sorting only by unit price cannot reflect the real business results.
Next step
Create weekly usage reports grouped by model, API, user, business function and error type. Fix infinite retries, history bloat, and tool loops first before considering more complex routing strategies.
When you need to compare multiple models or portals, useModel API comparison test templateUnifiedly record task completion rates, tokens, delays, errors and manual rework.