Calling a Model over HTTP
The chat request and response, every state of one request on screen, every HTTP failure and what to tell the user, timeouts and retries, and your own server route.
Phase 0 showed the three hops of an AI feature. This phase makes the middle one solid. You will learn what a chat request and a chat response really contain, field by field, and what each field means for your screen: the roles, the text, the reason an answer stopped, and the token counts.
Then you will learn what goes wrong and what to do about it. Every request lives in one of four screen states (idle, loading, success, error). Every failure has a real symptom: a 400, a 401, a 429 with a wait time, a 500, a gateway that answers with a web page instead of JSON, a phone that is offline. Each one deserves its own honest message, and none of them should ever show the provider's raw words to a visitor.
You will add timeouts, retries with backoff and jitter, and the rule for requests that must never be repeated. You will write the server route that holds your secret key and distrusts the browser. Every example runs real browser code against a scripted stand-in model, so it works with no account and prints the same thing every time. The phase ends with Mitra v1: a shop assistant that answers reliably, with every state handled and no streaming yet. (Streaming arrives in Phase 2, on top of this foundation.)
Practise this phase
Hands-on exercises: write the code, see your page live, and press Check to have it tested automatically.