AI API Pricing: Input vs Output Tokens, Caching, Batch
In this article
AI API pricing is primarily determined by the number of tokens processed, with distinct rates for input and output tokens, and discounts available for cached tokens and batch processing. This article explains how these pricing components work, how to estimate costs, and how to choose the most economical option for your use case.
in t | Input tokens | tokens | 1000 | 0 in o | Output tokens | tokens | 500 | 0 in ic | Input cache read tokens | tokens | 0 | 0 in ib | Input batch tokens | tokens | 0 | 0 in ob | Output batch tokens | tokens | 0 | 0 in p_i | Input price per 1M tokens | USD | 3.00 | 0 in p_o | Output price per 1M tokens | USD | 15.00 | 0 in p_c | Cache read price per 1M tokens | USD | 0.30 | 0 in p_ib | Batch input price per 1M tokens | USD | 1.50 | 0 in p_ob | Batch output price per 1M tokens | USD | 7.50 | 0 out cost | Total cost | USD | (t/1000000)*p_i + (o/1000000)*p_o + (ic/1000000)*p_c + (ib/1000000)*p_ib + (ob/1000000)*p_ob | 4
Formula
The total cost is the sum of each token category multiplied by its respective price per million tokens:
Total Cost = (Input Tokens × Input Price) + (Output Tokens × Output Price) + (Cache Read Tokens × Cache Read Price) + (Batch Input Tokens × Batch Input Price) + (Batch Output Tokens × Batch Output Price)
All token counts are divided by 1,000,000 to convert from per-million pricing. Variables:
- Input tokens: tokens in your prompt (including system messages and conversation history).
- Output tokens: tokens generated by the model in response.
- Cache read tokens: input tokens that were previously cached and are now being read from cache.
- Batch input/output tokens: tokens processed via the asynchronous batch API, typically at a 50% discount.
- Prices: per 1 million tokens, in USD. These vary by provider and model.
Worked Example
Using the default values from the calculator: 1,000 input tokens, 500 output tokens, no cache or batch tokens, input price $3.00/M, output price $15.00/M.
- Input cost: (1,000 / 1,000,000) × $3.00 = $0.003
- Output cost: (500 / 1,000,000) × $15.00 = $0.0075
- Total cost: $0.003 + $0.0075 = $0.0105
So a request with 1,000 input and 500 output tokens costs about 1 cent at these rates.
How Token Pricing Works
AI models process text in chunks called tokens. A token is roughly 4 characters or 0.75 words in English, but the exact tokenization varies by model. Prices are quoted per million tokens, and both input and output are billed separately. Output tokens are almost always more expensive than input tokens because generating text requires more computational resources than reading it.
For example, a model might charge $3 per million input tokens and $15 per million output tokens. A typical chatbot exchange with a 500-token prompt and a 200-token reply would cost: (500/1M × $3) + (200/1M × $15) = $0.0015 + $0.003 = $0.0045, less than half a cent.
Caching Discounts
Many providers offer prompt caching, where repeated input tokens (like system prompts or long conversation histories) are stored temporarily. When those tokens are reused, they are charged at a much lower rate—often 10% of the standard input price. For instance, if the normal input price is $3/M, cached input might be $0.30/M.
Caching is automatic in some APIs, while others require a cache_control parameter. The benefit is significant for applications with long, stable prompts, such as chatbots with extensive instructions or tools that process large documents. However, cached tokens expire after a few minutes (typically 5–60 minutes) of inactivity, so the discount only applies to frequent reuse.
Batch Discounts
Batch processing is for asynchronous requests that don't need immediate responses. You submit a file of many requests, and the provider processes them within 24 hours, usually at a 50% discount on both input and output tokens. For example, a batch input price might be $1.50/M instead of $3/M, and batch output $7.50/M instead of $15/M.
This is ideal for offline tasks like generating summaries for a large dataset, backfilling content, or running evaluations. The trade-off is latency—you get results in hours, not seconds. Batch APIs are not suitable for real-time user interactions.
How to Choose the Right Option
Your choice depends on your application's latency requirements and request patterns:
- Real-time apps (chatbots, autocomplete): use standard pricing, no batch.
- Long, stable prompts: enable caching to reduce input costs.
- Offline bulk processing: use batch API for up to 50% savings.
- Mixed workloads: combine caching for the real-time part and batch for the non-urgent part.
Also consider that some providers offer free tier credits or volume discounts for high usage. Always check the specific model's pricing page because rates vary widely—some models are 10× more expensive than others.
Common Mistakes and Misconceptions
A frequent mistake is ignoring the cost of output tokens. Many developers focus only on input price, but output can dominate the bill if the model generates long responses. For example, a 2,000-token output at $15/M costs $0.03, while a 500-token input at $3/M costs only $0.0015.
Another misconception is that caching always saves money. Caching only helps if you reuse the same tokens; if every prompt is unique, you'll still pay the full input price. Also, some providers charge a small fee for writing to cache (e.g., $12.50/M for cache writes), so you need to factor that in.
Finally, token counts are not the same as character counts. A word like "unbelievable" might be split into multiple tokens, so always estimate using the provider's tokenizer tool, not a simple word count.
Frequently Asked Questions
How do I convert words to tokens?
As a rough rule, 1 token ≈ 0.75 words for English text. So 1,000 words ≈ 1,333 tokens. But the exact count varies by language and formatting (spaces, punctuation, code). Use the provider's tokenizer or API to get an accurate count.
What is prompt caching and how do I use it?
Prompt caching stores a prefix of your prompt (e.g., system instructions) so that repeated requests don't reprocess those tokens. You typically enable it by adding a cache_control parameter to the system message or by using the provider's default caching. The cached tokens are billed at a lower rate, but they expire after a few minutes of inactivity.
Is batch processing always cheaper?
Yes, batch processing is usually 50% cheaper than real-time for both input and output tokens. However, it requires you to submit a file and wait up to 24 hours for results. It's only worth it if you don't need immediate responses.
Why are output tokens more expensive than input tokens?
Generating text is computationally intensive because the model must predict each token sequentially, using more memory and processing power. Reading input tokens is a single forward pass, which is cheaper. Hence, providers charge more for output.
Can I use both caching and batch together?
Yes, many providers allow caching within batch requests. The batch discount applies to the base input/output price, and cached tokens within a batch are billed at the cache rate. This can lead to even lower costs for bulk processing of similar prompts.
Do all AI providers price the same way?
No, pricing structures differ. Some providers charge a flat rate per token regardless of input/output, while others have separate rates. Some include caching automatically, others charge extra. Always read the provider's pricing documentation for the specific model you plan to use.