Claude Certified Architect – Foundations Practice Question 50: Token Counting Before Send

Claude Certified Architect, Foundations · Test 5 · question 10 of 10

Context Management & Reliabilitymedium

A document-analysis service assembles requests from a system prompt, tool definitions, a chat history and user-uploaded PDFs. Some requests exceed the model's context window and fail, and finance wants to estimate the input cost of large requests before committing to them. The team wants a way to learn the input size of the exact request, without generating a response and without paying for the check. What should they use?

Select one answer
Show answer and explanation

Answer:

  • D. Call the token counting endpoint (/v1/messages/count_tokens) with the same model, system, tools and messages to get the input token count before sending.

The token counting endpoint accepts the same structured input as message creation, including system prompts, client tools, images and base64 PDFs, and returns the total input tokens without creating a message. It is free to use, subject to its own requests-per-minute limits, which are separate from message creation limits. The count is an estimate that can differ slightly from actual usage, and it is tokenizer-specific, so you should count against the model you plan to use (newer models use a tokenizer that can produce roughly 30 percent more tokens for the same text). That makes it suitable for checking a request fits the context window and for estimating cost.

A is wrong because characters divided by four is a rough heuristic, not a count, and it ignores tool definitions and PDFs. B is wrong because it actually runs billable inference on every probe, and it also still starts generation. C is wrong because a generic tokenizer does not match Claude's tokenizer and cannot account for images, PDFs or tool definitions, and counts differ between Claude model generations.

Reference: Token counting

Practice Test 5 ›

Study guides for Claude Certified Architect, Foundations