Skip to content
mentoor

Topic 1 of 6 · 4 min read

Input, output, cached and thinking tokens

Goal: Calculate the cost of one API call from its token counts and a provider's price table.

An API call has no single price: you pay one rate for the tokens you send, a higher rate for the tokens the model writes, and special rates for cached and reasoning tokens. Prices are quoted per million tokens, so a call is a small multiplication.

Check yourself · 1 of 3

A provider charges $2 per million input tokens and $10 per million output tokens. Why is the output rate higher?

Choose one answer

Why it matters

A token is a small chunk of text, roughly three quarters of an English word. Every call is billed from the token counts the provider returns, not from the number of questions you asked. If you only read the headline price, you will misjudge the bill, because the headline is usually the input rate.

The four meters

  1. Input tokens. Everything you send: the system prompt, the chat history, pasted documents, tool definitions and the new question.
  2. Output tokens. Everything the model writes back. These cost more per token than input, often several times more, because the model produces them one at a time.
  3. Cached input tokens. If the start of your prompt repeats between calls, the provider can reuse it. A cache read is billed at a fraction of the normal input price. Writing to the cache can cost slightly more than a normal input token. See the prompt caching docs for each provider's rule.
  4. Thinking (reasoning) tokens. Reasoning models write hidden working steps before the answer. You do not see them in the reply, but they are billed at the output rate.

How to calculate one call

Take the token counts, divide by one million, multiply by each rate, add up. Use a made-up model priced at $3 per million input and $15 per million output.

Part Tokens Rate per million Cost
Input 12,000 $3 $0.036
Output 800 $15 $0.012
Thinking 3,000 $15 $0.045
Total $0.093

The answer is 800 tokens, but the thinking made the call almost twice as expensive as it looks.

Before and after

Before: "The model costs $3 per million, and my reply is short, so each call is almost free."

After: "Input is $3 and output is $15 per million. My call sends 12,000 tokens, gets back 800, and the model thinks for 3,000 more, so it costs about 9 cents."

What goes wrong

  • Using one rate for everything and under-counting output.
  • Forgetting that the whole chat history is sent as input on every turn, so a long conversation costs more with each message.
  • Ignoring thinking tokens because they are not visible.

The usage field in the API response gives the real counts. Read it instead of guessing.

Examples

A call with a long pasted document

A user pastes a 40,000-token contract and asks for three risks. The reply is 500 tokens. At $3 input and $15 output per million, the call costs $0.12 for input and about $0.0075 for output. The document, not the answer, drives the cost.

Reading usage in code

u = response.usage
cost = (u.input_tokens * 3 + u.output_tokens * 15) / 1_000_000

The rates here are example values. Replace them with the current numbers from the provider's price table.

Key points

  • API prices are quoted per million tokens and split into input, output, cached input and thinking tokens.
  • Output tokens cost more per token than input tokens.
  • A cache read is billed at a fraction of the normal input rate, but only when the start of the prompt repeats.
  • Thinking tokens are hidden from the reply yet billed like output tokens.
  • The usage numbers in the API response are the source of truth for what a call cost.

Common mistakes

  • Applying the input price to output tokens.
  • Counting only the latest question and not the history that is resent with it.
  • Forgetting that reasoning tokens are billed.
  • Copying a price from a blog post instead of the provider's current table.

Check yourself · 2 of 3

A call sends 10,000 input tokens and gets 1,000 output tokens. Prices are $3 input and $15 output per million. What does it cost?

Choose one answer

Check yourself · 3 of 3

A reasoning model writes 4,000 hidden thinking tokens and a 300-token answer. How are the thinking tokens billed?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic