Skip to main content
Technical Enough
Next: Prompt like an engineer

Make your first model call

Chapter 3 of 10 in Add AI Features · 20 min

The investor meeting is tomorrow morning, and tonight you are working alone on the deck, putting together the demo slides for your expense assistant. An hour ago you ran the test receipt through the feature, got back "Coffee, 4.85, Blue Bottle", and put that screenshot on slide 9. You run it again to capture a cleaner image, and for the same receipt, through the same code, the feature returns "Blue Bottle Coffee, $4.85", so the screen no longer matches the slide; a third run returns a third version. Nothing changed between the runs, and you cannot say why the output changed. A library (one package of code doing one job, written by someone else) built the request, the reply came back through code you have never read, and you have never seen the full text of the one call your app is built around.

In The model is a part, not a coder you wrote the Component Spec for the AI feature you chose: the model's job, who calls it, who pays, and what reaches a stranger unreviewed. In this chapter we print one call from our own app in full, so you can see why replies vary between runs like the ones above and plan your feature around that variation.

One model call, printed in full

In our family nutrition app FuelTheFam, the fridge feature sends a photo of the user's fridge to a multimodal model (one that accepts images as well as text), and a shopping list comes back while they wait. Nobody on our team reads a list before a user sees it, so the request itself has to carry everything the feature needs. Here is that request as it leaves our server:

POST https://api.provider.example/v1/generate
Authorization: Bearer (our key, attached on the server)

{
  "model": "(the model we chose)",
  "instructions": "This is a photo of the inside of a home
    refrigerator. List every grocery item visible in the
    photo, one item per line, with no other text. Include
    only items visible in the photo. If the photo is too
    dark or blurry to read reliably, reply with exactly:
    RETAKE",
  "input": [
    { "type": "image",
      "data": "(the fridge photo, encoded as text)" }
  ]
}

The outer parts match the call you read in APIs, how systems talk to each other: the first line holds POST (the word that asks for new work) and the endpoint (the provider's address for this job); then comes the Authorization line; and the model field names the model that should run. Inside that wrapping are two working parts. The instructions state the job in exact words you could quote: ours asks for one item per line, limits the list to items visible in the photo, and asks for the single word RETAKE instead of a guess when the photo is unreadable. The input is whatever the user supplied, here a photo sent as a long block of encoded text (the image converted into letters and numbers so it can travel inside the request).

The Authorization line, a header (a line of information sent ahead of the request's body), carries the API key that tells the provider which account to bill. That is why the call runs on our server and never in a browser, the rule from Backend, where the real work happens.

Providers name these fields differently: OpenAI's current default, the Responses API, calls them instructions and input; Anthropic takes the instructions as a top-level system parameter; Gemini uses a system instruction field. All of them describe the same kind of request, a POST that carries your API key.

A model call is one request that carries your instructions, an input, and your API key, and most of what this part teaches is a change to the instructions or the input.

What comes back

The reply is also JSON, the plain-text format of labeled fields that the request uses, and the text the model produced is one field among several:

{
  "id": "resp_8f42a91c",
  "model": "(the model that ran)",
  "output_text": "whole milk\nlarge eggs\nbaby spinach\n
    strawberries\ncheddar cheese\nbutter\norange juice",
  "stop_reason": "complete",
  "usage": { "input_tokens": 1641, "output_tokens": 24 }
}

The id lets you match this response to the user's request that caused it, and the model field confirms which model ran. The output text is what the user gets: each \n is a line break, and the text reaches the user's screen exactly as it is. The stop reason says why the model stopped producing text; complete means it finished on its own, and a reply cut off by a length limit would say something different. The usage block counts the tokens sent and returned, the units your bill is based on (more on tokens below). Nothing in the reply says whether the list matches the fridge: there is no confidence score and no flag saying the answer is correct, so your feature's code still has to check the output.

The drawing shows this call as it happens: your request, a fridge photo plus an instruction to list what is in it, goes into the model; the reply comes back as tokens appearing one at a time; and a note says you pay for tokens in both directions. Its lower half shows the same request sent twice, with replies that begin differently; the next section prints both.

Same photo, different list

Now send the identical request twice and print both replies.

Run one:

whole milk
large eggs
baby spinach
strawberries
cheddar cheese
butter
orange juice

Run two:

milk
eggs
strawberries
spinach
cheddar
butter
orange juice

Both runs returned the same seven groceries. Run two left out the adjectives, put strawberries ahead of spinach, and used 18 output tokens where run one used 24, so the two runs did not even cost the same. Neither reply is more correct than the other: both follow the instructions, and for a shopping list the differences do no harm.

The reason is sampling. A database looks answers up, so the same query returns the same row every time. A model produces its reply one token at a time, and at each step it produces a ranked list of possible next tokens, each with a probability. The API does not always take the top one. It picks among the likely ones at random, with the more likely ones picked more often, and most providers call the setting that controls how random that pick is temperature. When a different token is picked at one step, every token after it builds on that different start, so the rest of the reply can come out differently. Nothing malfunctioned the night the screenshot stopped matching; the call worked as designed every time.

If you send the same request twice, the replies can differ without anything being broken, because the model produces each reply by sampling instead of looking it up. Design your feature for that variation instead of treating it as a bug.

Tokens: the unit you are billed in

The usage block is where your cost is counted. You met tokens in APIs, how systems talk to each other: a token is a chunk of text the provider counts and charges for, a short word or a piece of a longer one, usually a few characters long. A model takes text in and puts text out as tokens, and the places where one token ends and the next begins are not where you would guess:

You | have | straw | berries | and | a | dozen | eggs | .

That is nine tokens for a seven-word sentence: common short words are one token each, strawberries splits in two, and the period is a token of its own. Images are counted as tokens too, and here the photo is most of the input: of run one's 1,641 input tokens, the instruction text accounts for roughly sixty and the photo for nearly all the rest. You pay for the tokens in and the tokens out on every call, so instructions you send with every call are a cost you pay again each time. One fridge list, photo included, costs well under a cent at current mid-tier rates (the price of a provider's middle model); current prices are on the providers' pricing pages and in the Playbook's cost section, not in this chapter.

A token is a chunk of text, usually a few characters long, and every call charges you for the tokens you send plus the tokens you get back, photos included.

Why read the call when your coding tool writes it for you

It is true that you will never write this JSON by hand: your coding tool writes the route (the code on your server that handles the request), and a library from the provider builds the request. Knowing how to read the call is still what lets you tell your coding tool what to change. When our fridge feature misfired during the build, the reply was "Sure! It looks like you have milk, a dozen eggs, and some spinach in there," which is friendly to a person and breaks code that expects a plain list. Both the cause and the fix were in fields you have now read: the instructions allowed a sentence instead of a list, and Get output you can build on shows how to make the reply follow a fixed structure. Every remaining step in this part changes one of these fields, and you will be reviewing the request your tool builds.

Try it now

Set aside twenty minutes. You bring the Component Spec from The model is a part, not a coder, and you leave with your feature's first call, which every remaining drill in this part builds on. The running club's feature is its support assistant, and its first call answers one real question from the support inbox.

No setup: Provider consoles (web pages where you can run a model call by filling in a form) need an account and paid credits, so this path stays on paper and costs nothing. Label the parts of our fridge request: endpoint, key, model, instructions, input, and in the response the reply, stop reason, and usage. Then write your feature's request the same way on one page: instructions in exact words you could paste, one real input written out in full, and the reply you expect, line by line. For the club's support assistant, the instructions tell the model to answer a member's question in one or two sentences, using only the lines from the club's Help page pasted under them. The input is one question a member really sent, "how do I renew my membership?", and the expected reply names the Join page and the price of 40 dollars a year. Mark which parts of that expected reply may vary between runs, such as order and phrasing, and which must never vary, such as the price. The page is your feature's first call, written down and ready to run as soon as your tools are set up.

With your tools: Make the call for real. Open Claude Code in the running-club folder, or in your own project, and ask for a script in one file that sends your feature's instructions and one real input to a model and prints the whole raw response body, reading the API key from an environment variable (a setting stored outside your code). The running-club folder already has one: the Tidy page reads MODEL_API_KEY from the .env file. The script runs on your laptop and is not part of the site, so your live site does not change. Run it twice with the same input and compare the replies, the stop reasons, and the output token counts; the two calls together cost almost nothing. A provider console runs the same call behind a browser form (Anthropic's is called the Claude Console), but it needs a funded account, which is why the paper path exists. Same move in Codex or Cursor: ask for a single script that makes one call and prints the raw response, then run it twice. If nothing is installed yet, the Setup Clinic gets you running in one sitting.

Either path gives you the same artifact, your feature's first call: made live if your tools are running, or written down and ready to run once they are.

Chapter Summary

  • A model call is one POST request that carries your instructions, an input, the name of the model to run, and your API key.
  • Providers name the two fields differently (OpenAI's Responses API, Anthropic's top-level system parameter, Gemini's system instruction field), but the request follows the same pattern everywhere.
  • The API key travels in the request's Authorization header, so the call runs on your server and never in the browser.
  • The response body holds the text the model produced plus details you will rely on later: an id, the model that ran, a stop reason, and the token counts your bill is based on.
  • The same request can return a different reply on every run, because the model produces each reply by picking among likely next tokens at random (sampling), not by looking it up.
  • Never judge a feature on a single run; rerun the input and judge the range of replies, the habit that becomes the Proof Table.
  • A token is a chunk of text, usually a few characters long, and every call charges you for the tokens you send plus the tokens you get back, photos included.
  • One fridge list costs well under a cent at current mid-tier rates; current prices per token are on the providers' pricing pages and in the Playbook, not in chapter text.
  • You leave this chapter holding your feature's first call, live or on paper.
  • Next, in Write the prompt as a spec, not a sentence, you rewrite the instructions field you just wrote. Changing the instructions is the first rung of the customization ladder, the order this part follows for changing what a model does, cheapest first.

Sources

  • OpenAI Responses API documentation (last verified July 2026).
  • Anthropic Messages API documentation (last verified July 2026).
  • Google Gemini API documentation on system instructions (last verified July 2026).
  • OpenAI, Anthropic, and Google pricing pages for per-token rates (last verified July 2026).