Bird
0
0

Which key should you use to retrieve the total number of tokens used from a typical AI API response dictionary named response?

easy📝 Syntax Q3 of 15
Agentic AI - Agent Observability
Which key should you use to retrieve the total number of tokens used from a typical AI API response dictionary named response?
A'usage' -> 'token_count'
B'usage' -> 'total_tokens'
C'usage' -> 'tokens_total'
D'usage' -> 'token_usage'
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct key

    The standard key for total tokens in AI responses is 'total_tokens' inside 'usage'.
  2. Step 2: Verify other options

    Other keys like 'token_count', 'tokens_total', or 'token_usage' are not standard and will cause errors.
  3. Final Answer:

    'usage' -> 'total_tokens' -> Option B
  4. Quick Check:

    Check official API docs for exact key names. [OK]
Quick Trick: Use 'total_tokens' key inside 'usage' dict. [OK]
Common Mistakes:
  • Using incorrect or non-existent keys
  • Confusing 'total_tokens' with other similar names
  • Accessing keys outside the 'usage' dictionary

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes