Knowledge tree
Offensive Security
Shells
File Transfer
Web Applications
API Pricing
Providers normally publish prices per million tokens. The cost of a task depends on how much input is processed, how much output is generated, and how many times the application calls the model.
Input and output
The basic calculation separates input and output because they usually have different rates:
cost =
input_tokens × input_rate
+ output_tokens × output_rate
In a conversational application, input may include instructions, history, tool definitions, and previous results. Counting only the latest user message is not enough.
Billable output is not necessarily limited to visible text. For reasoning models, the API may include additional work in output usage or report it as a separate detail. The provider’s accounting definition determines the charge.
Cached input
When many requests share a large prefix, the provider may recognize it as cached input and apply a different rate. Stable instructions and tool definitions repeated on every turn are one example.
Caching does not make those tokens free. There may be a read rate and, depending on the provider, write charges or eligibility conditions. Savings depend on repeated content actually producing cache hits.
The calculation can be written as:
cost =
uncached_input × input_rate
+ cached_input × cached_input_rate
+ output × output_rate
For a real application, use the usage returned by the API rather than trying to reconstruct it only from visible text.
Context growth
In an API that resends conversation history, later turns process part of the earlier context again.
The four calls process 5K + 8K + 12K + 16K = 41K input tokens. Looking only at the final 16K turn understates the accumulated work.
Compaction, context selection, and caching can change this curve. Measure every call because final conversation size does not represent all billed input.
Agents and subagents
One user task may trigger many agent inferences:
- The model decides to call a tool.
- The result returns as new input.
- The model chooses another action.
- Tests, retries, or validation add more iterations.
Cost accumulates on every call. Delegating to subagents adds separate contexts and loops. Parallel execution may reduce elapsed time while increasing total usage if it introduces more inference work.
Reasoning effort can also change token use and the number of steps. Agent cost should therefore be measured from real runs, not from the number of user messages.
Dated example
The standard text rates for GPT-5.6 Sol, checked on 2026-08-28, were:
- Input: $4.00 / 1M tokens.
- Cached input: $0.40 / 1M tokens.
- Output: $20.00 / 1M tokens.
For 1,000 requests with 20K uncached input tokens and 2K output tokens each:
input = 1,000 × 20,000 = 20M tokens → 20 × $4 = $80
output = 1,000 × 2,000 = 2M tokens → 2 × $20 = $40
-----
$120
If 15K of the 20K input tokens per request were billed as cached input:
uncached input = 5M × $4.00 = $20
cached input = 15M × $0.40 = $6
output = 2M × $20 = $40
---
$66
This is a calculation example, not a forecast. The model page also applies higher rates to requests above 272K input tokens and charges cache writes separately. Recheck current rates and conditions before budgeting.
What to measure
To understand task cost, record the model, usage for each call, cache hits, and any additional tool fees. Then compare cost with task result, latency, and success rate.
Optimization does not mean always choosing the cheapest model. It means finding the lowest-cost configuration that still completes the work at the required level.