Skip to content
AgenticAIWiki
  1. Learn
  2. Part 1
  3. 3. Context windows, tokens and cost
  4. 3.2

Lesson 3.2 · 2 of 4 · 4 min read · Reviewed 24 Nov 2026

Input vs output tokens and how pricing works

By the end, you can

  • Explain input versus output token pricing.
  • Estimate the cost of a request.

The formula

cost = input_tokens  x input price per token
     + output_tokens x output price per token      (includes any thinking tokens)
     + cache writes and cache reads at their own prices (if caching is used)

Prices are usually quoted per million tokensToken: The unit a model reads and writes: a word, part of a word, a space or a symbol, mapped to an integer id.. The pricing page lists current rates for each model; they change, so don’t hard-code numbers you remember.

Thinking tokens are output tokens

Reasoning models (13.6) write a stretch of thinkingExtended thinking: A mode in which the model reasons step by step in thinking blocks before giving its final answer. before the visible answer. Providers bill those thinking tokens as output, whether or not you see them, and on a hard task they can be several times longer than the answer itself. On an agentAgent: A system where a model decides its own next steps, calling tools in a loop until the task is done. that thinks before every tool call, they are often the biggest line on the bill. Read them from the usage field, and set effort per route: low for lookups and labels, higher only where an evalEval: A repeatable test that measures how well an AI system performs on a set of cases with defined success criteria. shows it helps.

Why output costs more

Input tokens are processed together in parallel. Output tokensOutput tokens: The tokens the model generates in its reply, including any tool calls and thinking. are generated one at a time, each needing a pass through the model, so they cost more to produce.

A worked shape (no real prices)

request:  10,000 input, 500 output
model:    input price P_in, output price P_out (per token)
cost:     10,000 x P_in + 500 x P_out

If P_out is several times P_in, the 500 output tokens can still be a big share of the bill.

What moves cost most

Lever Effect
Model choice Biggest single factor (chapter 71)
Input size History, documents and tool results add up
Output length Ask for the format you need
Reasoning effort Thinking tokens are billed as output; lower effort on easy routes (13.6)
Prompt caching Repeated prefixes become much cheaper
Batch processing Lower price for work nobody waits on

The usage field on each response gives exact counts to compute real cost (67.6).

Key points

  • Model APIs charge per token, with separate prices for input and output; output usually costs more per token.
  • Cost per request = input tokens x input price + output tokens x output price, plus any cache reads and writes.
  • Prices differ by model and change over time; always check the current pricing page.
Hands-on labRuns in the Playground

Price a call from its usage

Compute a call's cost in credits from its usage field, input and output priced separately.

You will have: A script that prices one call, shows the output share and projects a daily cost.

Steps

  1. Make one call and print its usage.
  2. Price input and output tokens separately with the illustrative credit rates.
  3. Add them for the cost per call and work out the share that comes from output.
  4. Multiply by 5,000 calls for a daily figure.

Done when

  • Input and output are priced at their own rates.
  • The output share is printed as a percentage.
  • The daily figure equals the per-call cost times 5,000.

Open in the Playground No API key needed.

Starter code (Python)
import anthropic

client = anthropic.Anthropic()

# Illustrative rates in credits, not real prices: output costs 5x input per token.
IN_PER_1K, OUT_PER_1K = 1.0, 5.0

msg = client.messages.create(
    model="claude-sonnet-5-5",
    max_tokens=300,
    system="You are a concise assistant for a hardware shop.",
    messages=[{"role": "user", "content": "Explain the difference between a drill and an impact driver."}],
)
print("usage:", msg.usage)
# TODO: price input and output separately from msg.usage, add them, and print credits per call
# TODO: print the share of the cost that comes from output and the cost of 5,000 calls a day
Show a solution
import anthropic

client = anthropic.Anthropic()

# Illustrative rates in credits, not real prices: output costs 5x input per token.
IN_PER_1K, OUT_PER_1K = 1.0, 5.0

msg = client.messages.create(
    model="claude-sonnet-5-5",
    max_tokens=300,
    system="You are a concise assistant for a hardware shop.",
    messages=[{"role": "user", "content": "Explain the difference between a drill and an impact driver."}],
)
u = msg.usage
cost_in = u.input_tokens / 1000 * IN_PER_1K
cost_out = u.output_tokens / 1000 * OUT_PER_1K
per_call = cost_in + cost_out
print(f"usage: {u.input_tokens} input, {u.output_tokens} output tokens")
print(f"credits per call: {per_call:.3f} (input {cost_in:.3f}, output {cost_out:.3f})")
print(f"share from output: {cost_out / per_call:.0%}")
print(f"credits per day at 5,000 calls: {per_call * 5000:,.0f}")
Quick checkA request sends 10,000 input tokens and gets 500 output tokens back. What decides its cost?
How sure are you?
Pick an answer and how sure you are