Your first API call
Ten lines of code, one request, and a reply from a model. But the reply also tells you exactly what that sentence cost, and why it stopped where it did. Most people never look.
In this lesson you'll learn to
- Write a model API request (model, max tokens, messages) and read the reply (content, stop reason, usage).
- Work out what a call costs from its token usage and the price per million tokens.
- Use the stop reason to spot a reply that was cut off, and fix it.
- Recognise the same request and reply shapes across providers, and estimate a feature's monthly bill.
Create a free account to open this lesson
It's free. You'll get every free lesson, quizzes that save your progress, daily flashcards and streaks.