AI Engineering from Scratch / Stage 2. The model in the product
Your card asks a model for the first time: first in mock mode with no key, then through the live API with a server-side key, a timeout and a recorded call cost.
Outcome: `runs/first-call.json` + a log
The app calls the model with no timeout and no error handling. On the free tier the provider returns 429 "too many requests", the program crashes with a traceback, and the operator sees a blank white screen. Or everything works, but a month later a bill shows up, because nobody set a spend limit.
In this lesson you'll make your first call in the right order: first a mock with no key and no money, then a key for one provider in .env on the server with a spend limit, and only then a live request.
For this lesson you need: the ready-made code from the l06 tag, your evals/own.jsonl, 30 cases with known answers and the baseline from lesson 5, and the lesson-05 branch. At the start of the lesson, in the starter folder:
If the second command says the file doesn't exist, you don't have your own cases yet, and that's fine. If it says the lesson-05 branch doesn't exist, skip it. If git switch says the l06 tag doesn't exist, run git fetch --tags and try again. If git switch refuses because of uncommitted changes (often it's STATE.md), first save them on the lesson 5 branch: git add -A, then git commit -m "кінець уроку 5".
What changed in the contract. The contract is the CONTRACT.md file with the card fields and function names. Its version on this tag is 1.1, and the card stays the same as in lesson 5. The l06 tag adds live Anthropic, OpenAI and Gemini adapters behind the same call_model, a price file support/prices.py, one retry on a temporary error and a log at runs/calls.jsonl. The first version of make_card appears: it asks the model and, for now, accepts its answer without checking it. Lesson 8 adds the evidence checks. git diff --stat l05 l06 shows every changed file. If the output doesn't fit and there's a : at the bottom, press q to exit.
Recall. In lesson 3 the card logic moved from index.html into a Python service. Which reason for that move matters today?
A ticket card filled in by the model through call_model: first in mock, then through the live API of one provider. The key lives only in .env (a plain text file with secrets in the project's root folder), which is not in git, and the provider dashboard has a spend limit set. You can read a ModelResult (status, tokens, price, time) and you know what the program does for each status, including a timeout.
This lesson: ~3 live calls, ≈ $0.001 on the default model, or $0 in mock or on the Gemini free tier.
The lesson code is already in the l06 tag. You don't write the provider adapters yourself: you configure and test them. Update the libraries: