How Much Does an LLM API Call Really Cost? Tokens, Caching, and Batching Explained
Anyone building an application using the OpenAI, Anthropic, or Google API will sooner or later ask themselves: How much does this actually cost? The official price lists are transparent, but they don’t reveal how costs accumulate in a real conversation. This guide explains the mechanics behind it—from tokens to input/output to caching, batching, and overhead—and concludes with a sample calculation that shows why chatbot costs often end up being higher than expected.
1. What are tokens, and how are they calculated?
A token is the smallest unit into which a language model breaks down text. It is neither a word nor a letter, but a subword unit—typically 3 to 5 characters long, often a syllable or a frequently occurring fragment. English texts usually end up with about four characters per token, while German texts tend to have three due to the many compound words and umlauts.
Example: The sentence "Künstliche Intelligenz verändert die Arbeitswelt." is split into 9 to 12 tokens, depending on the model. The “ä” in “verändert” alone can be counted as a separate unit depending on the tokenizer, because it occurs less frequently than in the English training data corpus.
Important: Each provider uses its own tokenizer. OpenAI uses the tiktokenlibrary, while Anthropic and Google use proprietary methods. The same text might result in 140 tokens with OpenAI and 180 with Claude. If you want to calculate across models, you should determine the token count for each model separately.
Cost breakdown (per request)
2. Input tokens vs. output tokens
Every API request generates two types of data: input tokens (everything you send to the AI—system prompt, user question, chat history) and output tokens (the AI’s response). Both are billed separately, and output is typically 4–5 times more expensive than input.
The reason: Output tokens require more computational power from the provider. When processing the input, the model analyzes the entire text in a single pass. For the output, it must generate tokens sequentially, one by one—each new token requires a complete computational pass through the model. This does not scale linearly.
Practical implication: If your application generates long AI responses (such as summaries or creative text), output costs will be the dominant factor. For classification or routing tasks (short responses, lots of context), input costs will be the dominant factor.
3. Conversations: Why every request includes the entire conversation history
This is the biggest cost obstacle. An LLM has no memory between API calls. For a chat AI to know what was just discussed, the entire history up to that point must be sent along with every new message—including the system prompt, all previous user messages, and all previous AI responses.
Specifically: If a chatbot runs with an 800-token system prompt and 5 message exchanges, the system prompt is billed five times—once per request. Each new user question contributes not only its own text but also the entire stack preceding it.
Mathematically speaking, this is exponential growth: A conversation with 10 rounds doesn’t cost 10 times as much as one with a single round, but often 30–50 times as much. That’s why chatbots operated productively can quickly become expensive without optimization.
4. Cached Input and Batch Pricing — the two most important levers
Prompt Caching: Up to 90% off repeat inputs
Both OpenAI and Anthropic offer prompt caching. The idea is that the provider stores the beginning of a request (typically the system prompt) in a cache for 5 to 10 minutes. If another request with an identical beginning arrives within that time, the cached tokens are not reprocessed but retrieved from the cache—and billed at about 10% of the normal price (i.e., a 90% discount on the cached portion).
Important: The discount applies only to the cached portion, not to the entire request. For an 800-token system prompt within a 2,000-token request, the system prompt is discounted, while the rest of the request remains at the standard price. The actual cost savings are typically between 20% and 40%, not 90%.
Batch API: 50% discount for asynchronous workloads
If you don’t need real-time responses—such as for nightly data analysis, bulk classification, or machine translation—the Batch API offers a flat 50% discount on input and output. In return, you agree that results will be delivered within 24 hours, not in seconds.
Caching and batching can be combined. With properly configured pipelines, combined savings of 60–70% are realistic.
5. Context Window, Max Output, and Overhead Tokens
Three terms that appear in price lists and are often confused:
- Context Window — the maximum number of tokens a model can process in a single request (input and output combined). Current models such as Claude Sonnet 4.6 or GPT-5.4 support 200K to 1M tokens. If your conversation exceeds this limit, the API will fail—you’ll need to summarize or shorten the conversation.
- Max Output — the maximum length of a single response. Typically ranges from 8K to 128K tokens, which is significantly shorter than the context window, even if there were theoretically still space available.
- Overhead tokens — invisible control tokens that are added to every message. The model needs to know where a message begins, what its role is (system, user, assistant), and where it ends. Rule of thumb: 3 tokens per message plus 3 tokens for the request. In a chat with 6 messages, that’s 6×3+3 = 21 additional tokens that you don’t see anywhere, but you pay for.
6. Sample calculation: Customer support chatbot with 5 turns
Enough theory. Let’s look at a realistic use case: a support chatbot based on Claude Sonnet 4.6 ($3 / $15 per 1M tokens, cached input $0.30).
Assumptions:
- System prompt: 800 tokens (persona, instructions, knowledge snippet)
- Per turn: 50 tokens for user questions + 200 tokens for AI responses
- 5 rounds of conversation, cumulative scoring
| Gymnastics | Input | Overhead | Output | Total Turn |
|---|---|---|---|---|
| 1 | 850 | 9 | 200 | 1,059 |
| 2 | 1,100 | 15 | 200 | 1,315 |
| 3 | 1,350 | 21 | 200 | 1,571 |
| 4 | 1,600 | 27 | 200 | 1,827 |
| 5 | 1,850 | 33 | 200 | 2,083 |
| Total | 6,750 | 105 | 1,000 | 7,855 |
Three cost scenarios for this very conversation:
| Scenario | Per conversion | At 100,000 conversations/month |
|---|---|---|
| Standard (no caching, no batching) | $0.0356 | $3,560 |
| With prompt caching (system prompts cached starting from turn 2) | $0.0269 | $2,692 |
| With caching + batch API (50% discount) | $0.0135 | $1,346 |
Two observations from the table:
- Caching alone yields about a 24% reduction—not 90%, because only the system prompt portion benefits. The effect becomes more significant with longer system prompts or more turns.
- Caching and batch processing combined yield savings of about 62%. Those who can use both optimizations (i.e., don’t necessarily need real-time processing) can save around $2,200 per month—enough to more than justify the investment in a robust caching solution.
Conclusion
Token costs aren’t a mystery; they follow clear rules. Anyone who understands the three mechanisms—tokenization, conversation accumulation, and special pricing—can plan budgets realistically and implement targeted optimizations. Key takeaways:
- Output costs 4–5 times more than input — short answers save the most.
- In conversations, costs increase quadratically, not linearly.
- Prompt caching typically reduces costs by 20–40%, while batch processing reduces them by 50%.
- Overhead tokens are invisible but countable—and become significant in large numbers.
Glossary
- Batch API
- Asynchronous processing mode with a 50% discount on input and output. Responses are provided within 24 hours instead of in real time.
- Cached Input
- Input tokens that have already been processed in a previous call and cached by the provider. Billed at approximately 10% of the normal price.
- Context Window
- Maximum number of tokens a model can process in a single request (input + output combined).
- Input Token
- Token sent to the AI — everything in the prompt: system prompt, user message, chat history.
- Max Output
- Maximum number of tokens the model can generate in a single response. Must be less than the Context Window.
- Output Token
- Token generated by the AI in its response. Typically 4–5 times more expensive than the input.
- Overhead Tokens
- Invisible control tokens that every message in a chat request receives—typically 3 per message plus 3 for the entire request.
- Prompt Caching
- A mechanism that allows providers to cache recurring prompt components (typically system prompts) and bill them at the cached price for the next request.
- System prompt
- The instruction at the beginning of an AI request that defines the model’s behavior (persona, response style, constraints). Is sent again with every request in a conversation.
- Token
- The smallest processing unit of a language model. Subword-based, typically 3–5 characters long. Each provider has its own tokenizer.
- Tokenizer
- An algorithm that breaks text down into tokens. OpenAI uses
tiktoken; other providers use proprietary methods.
Prices as of May 2026. Check the providers’ official websites for current rates at any time.
