

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Build an AI Agent
incomplete
2: Python Setup
incomplete
3: OpenRouter API
incomplete
4: Token Metadata
incomplete
5: User Input
incomplete
6: Multiple Messages
incomplete
7: Verbose Output
incomplete
This lesson's interactive features are locked, please to keep using them
When using any LLM API, it's important to keep track of how many tokens you're consuming. Most APIs provide metadata about token usage in their responses, which can help you to monitor your consumption – and to try to avoid hitting rate limits.
The response object returned by chat.completions.create includes a usage property. The usage object has (among others):
prompt_tokens property, showing the number of tokens in the prompt that was sent to the model; andcompletion_tokens property, showing the number of tokens in the model's response.Let's make sure we can keep track of our usage, printing it along with the response if desired.
Prompt tokens: X
Response tokens: Y
You should also verify that the response's usage property is not None before trying to access its own properties. If it is None, that would likely indicate a failed API request, and you could raise a RuntimeError with a helpful message.
User prompt: Why is Boot.dev such a great place to learn backend development? Use one paragraph maximum.
Prompt tokens: 20
Response tokens: 101
Response:
Boot.dev excels by offering a highly interactive and gamified learning experience that goes beyond passive video tutorials. It provides hands-on coding challenges directly in your browser with immediate feedback and a structured curriculum, ensuring learners build foundational skills in key backend languages like Go and Python, alongside crucial concepts such as databases, APIs, system design, and testing. This practical, project-based approach, coupled with clear progression paths, makes it exceptionally effective for mastering the real-world skills required for a backend development career.
Submit the CLI tests.