AI engineering

Stage 2 · Lesson 1 of 9

The chat messages API

Prompting and model APIs

Every to a major provider has the same basic shape. You send a model name and a list of messages. Each message has a role: system (or developer) for your instructions, user for what the person typed, and assistant for the model's earlier replies.

You also send a maximum output length and sampling settings. You get back the reply, plus a usage count of the tokens used. The API is , meaning it remembers nothing between calls.

So a is your code adding each reply to the list and sending all of it again. Read the usage field on every response and log it, because that is your real cost. Learn one official (the provider's own library) properly before adding a framework. Then you know what a request looks like when something breaks.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

Practise

  • Run open models locally to test prompts and sampling settings at zero API cost

Keep handy

Also worth your time

Mark this stage as not done?