Your First LLM API Request
Send your first request to a language model API from code, read the reply and understand every field.
A taste of a lesson
My reply ends mid sentence. Is the model broken?
Almost certainly not. Look at the stop reason field in the response. If it says the answer stopped because of the length limit (providers name this slightly differently), the model simply ran out of the output tokens you allowed. Raise the maximum output tokens in your request, or ask for a shorter answer in your instructions. Then check the usage numbers: output tokens should now be below your limit. What value did you set for the maximum output length?
Written by the teacher as an example. In your lesson the tutor answers your own questions, and like any AI it can be wrong.
What you will be able to do
- Create, store and load an API key without exposing it
- Send a request with a model name, messages and a length limit
- Read the reply's text, stop reason and token usage
- Explain why the API forgets previous calls and how history is sent
- Fix authentication, model name, bad request and rate limit errors
Lesson plan
- 1 Keys, accounts and spending limits Set up an API key safely and protect yourself from surprise bills. Start
- 2 Anatomy of a request Build a minimal request and know what each part does. Start
- 3 Reading the response Extract the text, stop reason and usage numbers from a reply. Start
- 4 Changing one thing at a time See how instructions, length limits and history change the output. Start
- 5 Conversations are sent, not remembered Build a two turn exchange by sending earlier messages back with each call. Start
- 6 Day one errors and how to fix them Diagnose the common errors from their codes and messages. Start
Try asking
About this tutor
For developers and technical beginners who have used chat assistants but never called a model from their own code. You get an API key and store it safely, send a first request with a short Python script, and read the response: the generated text, why it stopped, and how many tokens it used. Then you change one thing at a time (instructions, length limit, conversation history) to see the effect, and learn to handle the errors everyone meets on day one. Code stays short and generic, so it applies whichever provider you choose, and the tutor explains where providers differ.
Reviews
4.7
3 ratingsSample
- Ahmed Z.Sample
Printing the whole response first and reading it field by field made the structure obvious. The stop reason exercise explained my cut off answers immediately.
- Kwame B.Sample
Clear and generic enough to work with the provider I picked. The stateless explanation was the big lightbulb moment for me.
- Julia W.Sample
Free and properly useful. It refused to let me paste my key in the chat and showed me how to use a .env file instead.
About the teacher
Teaches developers and product teams to make their first LLM API calls and design simple apps around them
9 tutors 337 lessons taught Sample
I help people go from having used a chatbot to having an app that calls a model. I built web products for a long time and moved into LLM features when they started appearing in every roadmap, so my lessons focus on the decisions that matter in a first build: how a request is shaped, how a conversation is stored,...
See Gabriela's profile and tutorsMore like this
Other tutors on the same or nearby topics.