API Pricing

Token-cost calculation for one request and for agent sessions where context is processed repeatedly across many calls.
Updated 11 Oct 2026

Providers usually publish prices per million tokens. The real cost of a task depends on input processed, output generated, and how many calls the application makes.

Input and output

The basic calculation separates input and output because they normally have different rates:

cost =
    input_tokens  × input_rate
  + output_tokens × output_rate

In a conversational application, input can include instructions, history, tool definitions, and earlier results. The latest user message is only part of the material being processed.

For reasoning models, billable output may include work that is not visible as final text or that the API reports separately. Cost calculations should use the usage categories defined by the provider.

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 a common example.

Cached tokens may have a read rate, eligibility conditions, and, depending on the provider, a write charge. 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.

Context growth

In an API that resends conversation history, later turns process part of earlier context again.

Input growth across a stateless multi-turn sessionA simplified four-turn example processes 5K, 8K, 12K, and 16K input tokens. Although the final request contains 16K input tokens, cumulative processed input across the session is 41K tokens.051015↑ Input tokens (K)Turn 1Turn 2Turn 3Turn 45K8K12K16KInput growth across a stateless multi-turn sessionA simplified four-turn example processes 5K, 8K, 12K, and 16K input tokens. Although the final request contains 16K input tokens, cumulative processed input across the session is 41K tokens.051015↑ Input tokens (K)Turn 1Turn 2Turn 3Turn 45K8K12K16K
41K cumulative input across four turns
Figure 1. Four requests end with 16K tokens of context but process 41K input tokens in total.

In the example, the four calls process 5K + 8K + 12K + 16K = 41K input tokens. The final 16K describes the ending context size, not all accumulated work.

Compaction, context selection, and caching can change that curve. Cost calculations need the usage for each call.

Agents and subagents

One user request can trigger many inferences:

  1. The model decides to call a tool.
  2. The result returns as new input.
  3. The model chooses another action.
  4. Tests, retries, or validation add more iterations.

Every call adds input and output. A subagent also adds its own context and loop. Parallel execution can reduce elapsed time while increasing total usage.

Reasoning effort can change both token use and the number of steps. Agent cost is therefore measured from real runs rather than the number of visible 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:

Operation (tokens × rate / 1M)Cost
Input: 20M × $4$80
Output: 2M × $20$40
Total$120

If 15K of the 20K input tokens per request were billed as cached input:

Operation (tokens × rate / 1M)Cost
Uncached input: 5M × $4.00$20
Cached input: 15M × $0.40$6
Output: 2M × $20$40
Total$66

This is a calculation example, not a forecast. The model page also applied higher rates to requests above 272K input tokens and charged cache writes separately. Recheck current rates and conditions before budgeting.

What to record

To compare configurations, record the model, usage for each call, cache hits, and any additional tool charges. Then compare that cost with latency, success rate, and result quality on the task that matters.

References