6/17
Part 3 of 7 · Counting tokensLearn and do

Reserve the answer's tokens, or count them as they're written

An answer's length isn't known until it ends, so providers count it two ways:

  • Reserve up front. OpenAI's docs say a request counts as the larger of its max_tokens and an estimate from its character count.
  • Count as it's written. Anthropic's docs say output tokens are counted in real time as they're produced, and max_tokens doesn't factor in. Input tokens are estimated at the start and adjusted.

Say the shop's own limiter gave the assistant 400,000 output tokens a minute and reserved max_tokens when each answer started:

OTPM = 400_000
for max_tokens in (4_096, 300):
    print(f"reserving max_tokens {max_tokens:>5,}: {OTPM // max_tokens:>5,} answers can start in a minute")
print(f"counting the 250 tokens actually written: {OTPM // 250:,}")
Predict

Answers average 250 tokens, but each one reserves a max_tokens of 4,096. How many answers can start in a minute under 400,000?

Pick one to see what it prints.
Pick an answer above to see the rest