Skip to content
Clairos Learn

Inference requests and APIs · Lesson 5 of 16 · 7 min

Inspect token usage

Usage accounts for input and generated tokens separately. Compare the sum with the recorded total and keep the tokenizer/model context with any estimate.

Mastery 0/3Run itExplain itApply it
learner@clairosSimulated AI Ops lab
learner@clairos:~ $
↑ history · Tab complete · Ctrl+C cancel · Esc, Tab to leaveExit 0

Understand the pattern

Usage accounts for input and generated tokens separately. Compare the sum with the recorded total and keep the tokenizer/model context with any estimate.

Interpret the evidence

Record 520 total tokens, with 400 input and 120 output.

A tempting mistake

Count only generated output as total token usage.

All names, measurements, prices, versions, and thresholds in this exercise are fictional training data. The evidence supports this bounded scenario, not a claim about a live provider.

Worked example and expected result
$ cat /opt/ai-lab/cases/aiops-inference-apis-005.json
{
  "fixture": "Fictional training data; not a live measurement.",
  "input_tokens": 400,
  "output_tokens": 120,
  "total_tokens": 520
}

Exit status: 0. The command completed successfully in the training fixture.

$ jq .total_tokens /opt/ai-lab/cases/aiops-inference-apis-005.json
520

Exit status: 0. The command completed successfully in the training fixture.

$ printf '%s\n' 'record-520-tokens' > /home/learner/lab/aiops-inference-apis-005-decision.txt
(no output; exit 0)

Exit status: 0. The command completed successfully in the training fixture.

Try a variation

Name the assumption that would have to change for “record-520-tokens” to stop being the justified action. Do not silently replace missing evidence with a guess.

Explain it

What does the evidence in “Inspect token usage” justify?

Apply it elsewhere

A colleague concludes: “Count only generated output as total token usage.” What should you do?

Keep the momentum.

Complete the lab, then explain and apply the pattern.

Next: Distinguish client and server errorsTry an incident drill

Anonymous lesson and mastery progress lasts for this session. Sign in to keep synced lesson XP between sessions; mastery stays device-local. No speed bonus, lost lives, or hint penalties.

Keep learning

  1. 01Read a response envelopeA response envelope contains output plus metadata such as completion status and usage. Inspect the finish reason before treating partial output as a complete answer.Practice
  2. 02Distinguish client and server errorsClient and server status classes point to different boundaries. A malformed request calls for correction, while a transient server failure may warrant a bounded retry policy.Practice
  3. 03Reason about timeoutsTimeouts must identify which layer stopped waiting. If the client deadline is shorter than normal server work, the client can time out while the server keeps processing.Practice