Codex

How Codex counts tokens: input, cached, and output

A worked explanation of Codex token fields: what input includes, how cached input is counted, and where reasoning tokens appear.

Quick answer

Codex reports input, cached input, output, and reasoning tokens. Cached input is part of input, not a separate addition. Reasoning tokens are billed with output but often shown separately. To get fresh input, subtract cached from total input; to get billable output, use the output total as reported.

A worked example

Suppose a turn reports input 40,000, cached 32,000, output 1,200, reasoning 600.

FieldReportedWhat it means
Input40,000All context sent
Cached input32,000Part of the 40,000 served from cache
Fresh input8,00040,000 minus 32,000
Output1,200Generated tokens
Reasoning600Shown separately, billed with output

Adding 40,000 and 32,000 double counts. Adding 1,200 and 600 may double count too, depending on whether the output total already includes reasoning. Check the label in your view.

Why the split exists

  • Cached input is cheaper, so providers report it separately.
  • Reasoning is invisible to the user but consumes compute.
  • Input grows with conversation length; output does not.
  • The split lets you see whether context or generation is the cost.

Use the fields correctly

  1. For total tokens sent, use input.
  2. For cost, apply the cached rate to cached input and the input rate to the remainder.
  3. For generation cost, apply the output rate to output.
  4. Never add cached to input.
  5. State which convention you use when comparing tools.

What the counters include

FieldCountsGrows with
InputEverything sentFiles, history, instructions
Cached inputReused prefixLong stable prompts
OutputGenerated textEdits and explanations
ReasoningInternal thinkingHard problems
TotalBilled or reported sumAll of the above

Two tools can disagree because one counts reasoning as output and the other reports it separately, or because one includes cached tokens in the input total. Neither is wrong; they answer different questions.

The cached input guide explains the discount, and why usage numbers differ covers cross-tool mismatches.

Questions, answered

Is cached input included in the input total?

Yes. Cached input is a subset of input, reported separately so it can be priced lower.

Are reasoning tokens included in output?

They are billed as output. In some views they appear as a separate line, so check before adding both.

Why do two tools report different totals for the same session?

One may include cached input in its total and the other may not. Compare the field definitions, not just the headline number.

Browse by topic