What to know first
The general formula is input tokens × input rate plus cached input × cache rate plus output tokens × output rate, divided by 1,000,000, followed by any applicable tool, container, file-search, or storage charges. The worked rates below illustrate the method; always use the target model's current pricing page for production estimates.
Separate the four cost categories
Input tokens include prompts, conversation history, tool definitions, and files sent to the model. Cached input is the portion reused by prompt caching. Output tokens include visible output and, for reasoning models, internal reasoning tokens. Tools and storage can be billed separately by call, runtime, or capacity.
The same text can produce different token counts across models, encodings, and languages. A complete request can also include message structure, tool schemas, images, and files, so counting visible characters is not enough.
| Component | What it represents |
|---|---|
| Input tokens | Content sent into the model |
| Cached input | Reused input with its own applicable rate |
| Output tokens | Visible output and reasoning tokens |
| Tools/storage | Search, containers, file search, or storage charges |
Sources: OpenAI: Understanding and counting tokensOpenAI API: Pricing
A reproducible single-request formula
Let P_in, P_cache, and P_out be the per-million-token rates, and let T_in, T_cache, and T_out be the measured usage. Split input into uncached and cache-hit input so cached tokens are not charged again at the standard input rate.
When a request invokes a tool, add the tool's call, runtime, or capacity charge from the official pricing page. Batch, regional processing, fast modes, or long context can have different rates and should be separate budget rows.
Token cost = (T_in × P_in + T_cache × P_cache + T_out × P_out) ÷ 1,000,000
Total request cost = token cost + tool calls + container/file-search/storage charges
Worked example: why is the request $0.383?
Assume a model charges $2 per million regular input tokens, $0.10 per million cached input tokens, and $10 per million output tokens. The request contains 120,000 input tokens, 30,000 of them cache hits, and 20,000 output tokens. Ignore tools for this example.
Uncached input is 90,000: 90,000 × 2 ÷ 1,000,000 = $0.18. Cached input is 30,000 × 0.10 ÷ 1,000,000 = $0.003. Output is 20,000 × 10 ÷ 1,000,000 = $0.20. The total is $0.383.
| Item | Usage | Rate per million | Subtotal |
|---|---|---|---|
| Uncached input | 90,000 | $2.00 | $0.180 |
| Cached input | 30,000 | $0.10 | $0.003 |
| Output | 20,000 | $10.00 | $0.200 |
| Total | — | — | $0.383 |
Scale one request into a monthly budget
If there are 500 similar requests per day for 30 days, the reference token cost is 0.383 × 500 × 30 = $5,745. This is a scaling example; production budgeting should use measured input length, cache ratio, output limits, and retry rate.
A better forecast has low, base, and high scenarios, with tool calls and long-running tasks listed separately. Do not rely on one average message length because an agent's history and tool results grow throughout a task.
Monthly reference cost = single-request cost × daily requests × billing days
Budget cap = low/base/high scenario cost + retry and tool buffer
Sources: OpenAI API: PricingOpenAI: Understanding and counting tokens
Make the real bill traceable
- Log the model, input tokens, cached tokens, output tokens, and tool calls for each request.
- Use the target model's tokenizer or complete-request counting API instead of replacing tokens with character counts.
- Treat long context, images, files, and tool schemas as part of input cost.
- Include retries, requests that eventually succeed after a timeout, and peak concurrency in the forecast.
- Re-read the official rate card when prices change instead of hard-coding an old rate forever.
Sources: OpenAI: Understanding and counting tokensOpenAI API: Pricing
Frequently asked questions
Are token costs charged per message?
No. API billing is based on input, cached input, output, and reasoning tokens, with possible additional tool or storage charges.
Sources: OpenAI: Understanding and counting tokensOpenAI API: Pricing
Why can a short visible answer use many output tokens?
Reasoning models can use hidden reasoning tokens that count as output usage. Tools, context, and message structure can also add input tokens.
Is cached input free?
Not necessarily. Cached input normally has its own rate; check whether caching is active and which rate applies to the model.
How do I estimate a monthly API budget?
Calculate one request with the formula, multiply by volume, then add tools, storage, retries, and peak buffers. Correct the assumptions with real usage logs.
Sources: OpenAI API: Pricing
Official sources and review notes
Sources checked on October 17, 2026. Rates and eligibility rules can change; confirm the latest official guidance and your own agreement.
AISub prepared this guide from public OpenAI documentation, with an independent worked example and purchasing advice. AISub is an independent price index and is not affiliated with OpenAI.
