Module 1 · Lesson 1 of 6
One model call, end to end
Predict first: does the whole answer come back, and who can read the key? Step through to check.
- User's browser — runs the page — healthy — NOW — question sent
- Your server — holds the API key — healthy
- Model API — the provider — healthy
- Request
- Reply
Step 1 of 8 · User's browser
Done: The page sends the question to your server
- What happens
- The user asks: "Can I return shoes I bought 40 days ago?" The page sends this to your own server, not to the provider.
- Why
- Your server holds the secret API key. The page runs on the user's device, where anyone can read its code.
- What changes
- Your server has the question. Nothing has gone to the provider yet.
- Next
- Your server builds the messages
Event log
7 more to go. Press a line to go back to that step.
The request appears here once it has been built.
Step 1 of 8: User's browser. The page sends the question to your server. The user asks: "Can I return shoes I bought 40 days ago?" The page sends this to your own server, not to the provider.
What this simplifies. The shop, its policy and the answer are made up, and the model's reply is written in advance. Tokens are counted by this site's teaching splitter, so a real model counts a few more or fewer. Field names differ between providers: one says "finish_reason" where another says "stop_reason", and some take the instructions outside the message list. The shape is the same: messages and settings go in; text, a stop reason and token counts come back. Prices are examples.
Most AI features call a model through a provider's API. Your server sends an (The rules an app or browser uses to ask a server for something and get an answer, such as GET /profile/42 and then 200 OK.) request with messages and settings, and gets back a reply with the answer.
The messages each have a role. A (The part of a model request that holds your instructions and context, kept apart from what the user typed.) holds your instructions and context. User messages hold what the user typed, and earlier model replies go back in as assistant messages.
Settings travel with the messages: which model, the most (A piece of text that a language model reads or writes, often part of a word. Prices and limits are counted in tokens.) the answer may use, and a (A request setting that controls how much chance goes into picking each next token. Low gives repeatable answers; high gives varied ones.). The reply holds the text, a (A field in a model reply that says why the answer ended: it was complete, or it reached the token limit set in the request.), and the tokens that went in and out.
The (A secret string that tells a model provider which account is calling, and so which account pays. Keep it on your server, never in a web page.) tells the provider which account pays. Keep it in your server's secret settings. A key inside a web page can be read and copied by anyone who opens the page.
In system design: Your server sits between users and the provider. It holds the key, builds the messages, sets limits, reads the stop reason and records token use per customer.