In brief
The cost of a language model API is the sum of input tokens and output tokens multiplied by the provider's rates, with output costing more than input. When a model works with tools, every round sends it the whole conversation so far, so input grows with each step. Three things lower the bill: prompt caching for the fixed start of the prompt, batch processing for cases that can wait, and the smallest model that passes your tests. Cost is calculated per case, not per request.
What the bill is made of
Model providers bill by tokens, the chunks of text a model splits words into. In a single request you pay for several kinds of tokens:
| Item | How it is counted | What to watch |
|---|---|---|
| input tokens | everything you send: prompt, rules card, document, conversation history | grows with every round of the tool loop |
| output tokens | everything the model generates | priced higher than input |
| reasoning tokens | the internal "thinking" of models that have it | billed as output, even though you often do not see them |
| tool definitions | tool names, descriptions and schemas | added to input on every request |
| images and PDF pages | converted to tokens by size | a scanned page can cost more than its text |
| prompt cache | separate rates for writing and reading | pays off only with a repeated prefix |
Rates change often and differ between models from the same provider, so in your calculation take them from the vendor's current price list, not from an article.
A token is not a word: how to size one case
Token count depends on the language and the model's tokenizer. Polish text usually produces more tokens per word than the same text in English, because tokenizer vocabularies were built mainly from English text. Instead of guessing, count tokens on a sample of documents: providers offer dedicated API functions for that.
An example for the math: an AI Worker codes an invoice in four rounds with tools. The fixed prefix (rules card and tool definitions) is 4,000 tokens, the invoice 2,500 tokens, each tool result 500 tokens and each model reply 300 tokens.
| Round | What is in the input | Input tokens | Output tokens |
|---|---|---|---|
| 1 | prefix, invoice | 6,500 | 300 |
| 2 | the same, reply 1, tool result | 7,300 | 300 |
| 3 | the same, reply 2, tool result | 8,100 | 300 |
| 4 | the same, reply 3, tool result | 8,900 | 300 |
| total | 30,800 | 1,200 |
The invoice is 2,500 tokens, yet the case uses more than 30,000 input tokens. At 800 invoices a month that is approx. 25 million input tokens and approx. 1 million output tokens. You multiply these by the rates from the price list. The same way you calculate how many rounds each extra tool adds, as described in How AI agents work inside.
Prompt caching: pay less for a repeated prefix
In the example above, the 4,000-token fixed prefix goes out in every round of every case. Prompt caching lets you pay less for it. The rules, according to provider documentation:
- The whole prefix must match. A cache read works only if the start of the request is identical to the character. Fixed elements (tools, rules card) go first, variable ones (document, date, case number) go last.
- There is a minimum length. A prefix that is too short is not cached.
- Entries are short-lived. By default from a few to a few dozen minutes, with a longer option at a higher write rate. Caching pays off with a steady stream of cases, not with one case an hour.
- Writes cost more, reads much less than ordinary input tokens. The saving appears when the same prefix is read many times.
The API response reports how many tokens were written to the cache and how many were read from it. If both are zero, caching did not work and you need to check what changes at the start of the request.
Batch processing: when the result can wait
Not every case has to be done in a second. Coding invoices for the morning list, classifying a backlog of emails or running an evaluation on a test set can wait. Providers offer batch interfaces for this: you submit many requests at once, results arrive asynchronously, and the documentation states a 50% discount compared with regular requests. One provider guarantees results within a 24-hour window, another says most batches finish in under an hour.
A batch does not suit a tool loop where each round depends on the previous one, but it fits a first step well, for example reading all documents that came in overnight.
Choosing a model: the smallest one that passes the tests
The largest model is not the default best choice. Smaller models are cheaper and faster, and for field extraction or classification they are often enough. A practical approach:
- Set a quality threshold on the test set, for example 97% field agreement with the reference.
- Test models from the smallest up. The first one to pass the threshold becomes the candidate.
- Consider splitting tasks. A small model reads the document and fills in fields, a larger one gets only cases flagged as hard.
- Limit output. A short answer in a schema instead of a description in sentences means fewer expensive output tokens.
- Measure cost per case after deployment, because production documents are often longer than test ones.
The comparison method is described in LLM evaluation. Model cost is only part of the bill: the full calculation including team time is in How to calculate whether an AI Worker pays off.
Your own server: a different calculation
With a model running on your own server you do not pay per token, but for hardware, power and maintenance. The cost of one case is the cost of an hour of server time divided by the number of cases the server handles in that hour. This math wins with a large, steady volume and loses when the server sits idle most of the day. Hardware and licenses are covered in Open source LLMs for business.
For AI Workers in IT and data from DYNAMINDS Labs, we calculate model cost during the pilot on the company's own data: per case, with caching and batching wherever the process allows.
Questions and answers
How much does one case handled by a language model cost?
It depends on document length, the number of tool rounds, the model and the provider's rates. Count input and output tokens on a sample of a few dozen real cases, multiply by the current price list and add a margin for cases longer than average. A calculation on a sample is more reliable than any average from the internet.
Why is the API bill higher than document length suggested?
Most often because of the tool loop, where each round resends the whole history, tool definitions added to every request, and reasoning tokens billed as output. Caching the fixed prefix, fewer rounds and shorter tool results all help.
Does prompt caching change the model's answers?
No. According to provider documentation, caching does not change the output; it only avoids reprocessing an identical request prefix. The answer is the same as without it, while the time and cost of processing the input change.
Does a cheaper model mean worse results?
Not always. In tasks such as field extraction, classification or price list checks, smaller models often score close to the largest ones. The difference shows up in long reasoning and unusual cases. A test on your set decides, not the price.