Skip to content
AI-Native PM

Wire the model into your build

Chapter 9 of 10 in Add AI Features · 30 min

The running-club site has been live for months, and members sign in, pay, and RSVP on it every day. One evening you ask the agent to add the support assistant to the site. It prints a plan, you approve it, and twenty minutes later you type a question into a chat box on your laptop and get the right time for the weekend run. The agent reports that the assistant is ready and asks whether to deploy it. You have not read the diff, the key the assistant uses exists only in the .env file on your laptop, and a deploy would put the change on the site that members are using tonight. If you say yes, the first person to find out whether the assistant works on the host will be a member.

You arrive from Choose the model you ship with a model chosen, a Proof Table of five real inputs, and a Model Spec with one field left to fill in. Your site is already live, you have reviewed it, and it has passed its pre-flight check, so adding the AI feature is a change to a live site. In this chapter you ask the agent for that change, review its diff, repeat the secrets and spending checks for the new key, and try the feature on a preview copy, all before any member can use it. The work takes about an hour. We start with the hour we spent wiring the fridge feature into FuelTheFam (connecting the model call to the app's code), because your hour follows the same steps, and then cover what a live site adds.

The project file: ten lines the agent reads before your first ask

Every session with a coding agent starts from zero: the agent gets no record of your site, your users, or your past decisions, and any gap you leave gets filled with generic defaults. So we started the hour with a project file. Claude Code, the coding agent we use, reads a file named CLAUDE.md in the project's top folder at the start of every session, and other tools follow the same convention with a file named AGENTS.md. On the day the fridge feature went in, ours held ten lines:

# FuelTheFam
FuelTheFam is a family nutrition app for busy parents.
A parent photographs the open fridge and a shopping list comes back
while they wait; a photo of a dinner plate becomes a nutrition estimate.
The model holds one runtime job per feature; everything else is code.
The API key stays on the server. Nothing sent to a browser carries it.
An unreadable photo gets a retake request, never a generated guess.
A confident nutrition number for an ambiguous plate must never ship.
Logging a full day of meals must stay under three minutes.
Keep every change small enough to read in one sitting.

The file says what the app is, who it serves, the model's job, and what must never reach a user. Then, as our first message in the session, we pasted in the feature's one-pager (the one-page description of the feature) whole. We saw the benefit at once: every plan and diff the agent generated followed our constraints, and nothing came back that we had not asked for in the one-pager. When you find yourself making the same correction in session after session, add it to the file too, so you only make it once.

Your project may already have this file from your earlier work with the agent. If it does, add the lines for the AI feature: the model's one job, where the key is kept, and what must never reach a user.

A project file is text the coding agent reads before your first word, so your constraints are part of every session from the start instead of something you have to repeat.

The ask, as we typed it

With the file in place, our ask, the message telling the agent what to build, was a single paragraph:

Add the fridge feature. When a user submits a photo, send it from our server to the multimodal model named in the config, using the prompt in prompts/fridge.txt exactly as written, and return JSON matching the one-field items schema.

The ask names the trigger (a user submits a photo), the route (the code on our server that handles the request), the prompt, and the structure of the reply (JSON, a text format code can read, in the one-field schema from Get output you can build on). Claude Code printed its plan before touching any files, which is the default in current coding tools, and we checked the plan against the one-pager before approving it. Then we ran the first photo in our Proof Table, our fridge holding milk, a dozen eggs, and some spinach, and got back a list of three items.

One trip around the loop: finding the flaw in the first draft

We work in a loop of four steps, drawn below: describe what you want, watch what the agent does by reading the plan it prints, verify the result, and correct it with specifics. In the opening scene you had run one question and the agent was offering to deploy, and that is the point where verifying starts. Verifying means doing two things: running a real input, which photo one just covered, and reading the diff the way you learned in Review what the AI built, which is where this draft failed. Our API key sat twelve lines into the new route file, pasted into the code:

const API_KEY = "sk-live-8f2..."; // fridge model key

The call still ran on our server, exactly as our project file requires, but a key written into the code is copied wherever the file goes: into git's history (git is the tool that keeps the project's save points), onto every laptop that copies the project, and into any repository (the project's shared copy) it gets uploaded to, where automated programs called scrapers search for strings like this one. We wrote the correction the way you would write a good bug report, naming the symptom, the place, and the behavior we wanted:

The API key is hard-coded in the new route file. Move it to an environment variable, and confirm no other file in the diff contains the key.

On the second pass the agent moved the key into an environment variable (a value a program reads from the place it runs, not from its code), and we reran photo one and got the same three items. We rerun the Proof Table after every change, so that a fix cannot break something that worked without our noticing.

Treat the agent's first response as a draft. You get a working feature by going around the loop, describe, read the plan it prints, verify by running an input and reading the diff, and correct with specifics, once for every change.

You might object that the agent wrote the code and the code ran, so it works. Both facts are true, and the conclusion is still wrong, because "it ran" and "it works" are different claims. A key pasted into the code works exactly like a safely stored one until the code leaves your machine, and the agent's summary of its own work sounds just as confident either way. That is why you decide from the diff and never from the agent's summary.

Sometimes another trip around the loop does not help. If the same correction has failed twice, stop and do what you learned in Work with your AI coding tool and get unstuck: go back to your last save point, start a new session, and ask again in a smaller step. The Playbook's kill rule gives you this as a checklist.

The wiring that makes the feature ready to launch

A feature that gives correct answers is still not ready to launch if you have not handled the wait, planned what happens when a call fails, or capped what the calls cost. We spent the rest of the hour on that wiring, one short ask for each piece.

The drawing traces the wiring. A request goes from the browser to your server route, where the key is kept, never in the browser; the server forwards it to the model; and the reply streams back to the browser. A fallback branch handles unreadable input by asking the user a question instead of guessing.

The call stays on the server. The photo is sent to our route, the server adds the key from its environment variables and calls the model, and nothing sent to a browser ever contains the key. Backend, where the real work happens explains why the call belongs there.

The answer streams. Streaming means the reply appears piece by piece as the model produces it, instead of all at once at the end. A spinner gives the parent nothing to read, while items arriving one by one show progress. One short ask turned streaming on: the parent at the open fridge sees milk appear while eggs are still on the way.

We decided what happens on failure before it happened. When the model reports that a photo is unreadable, the screen asks for a retake and never shows a guessed list, because a generated list looks exactly like a real one. We set the timeout at the same time: if nothing has streamed after ten seconds, the app stops waiting and offers a retry.

Spending gets a cap. One list costs a fraction of a cent at mid-tier rates (the price of a provider's middle model), so the spend cap we set in the provider console (the provider's website for your account) is there for the night a retry bug calls the model over and over in a loop. With the cap, you pay about the price of lunch for that night instead of whatever your card limit allows.

What to check before the change reaches your live site

Everything so far happens on your laptop. Members are already using your site, so the change goes through the steps below before it reaches them. You learned each step in an earlier chapter, and here you repeat it for one new feature.

  1. Read the whole diff before anything leaves your laptop. Ask the agent, "Show me everything that changed since the save point," and go through the answer the way you learned in Review what the AI built. A new feature should mostly add files of its own. If the diff also changes sign-in, payments, or a page you did not mention, ask the agent why before you go on.
  2. Give the feature its own key, and repeat the secrets check. Create a new key at the provider for this feature. With a key of its own, you can cancel it at the provider if it ever leaks, and the Tidy page keeps working on MODEL_API_KEY. Store the new key where you stored the first one: in the .env file on your laptop and on the host's Environment Variables screen, under a name such as ASSISTANT_API_KEY. Then run the secrets check from The pre-flight check: secrets, money, data, and the law again. In a Next.js project like the running club's, the name must not start with NEXT_PUBLIC_, because Next.js copies any value with that prefix into the JavaScript that every visitor's browser downloads. The key itself must not appear anywhere in the diff.
  3. Add a switch that turns the feature off. Ask the agent for one more environment variable, for example ASSISTANT_ON, and tell it to show the chat box only when the value is true, and to show the support address in its place when the value is false. This is the kill switch from the pre-flight check, the way to turn a feature off quickly, built for the new feature. On Vercel a changed environment variable applies only to deploys made after the change, so turning the feature off takes two steps: change the value, then deploy again.
  4. Check the spending cap. Open the provider's billing page. If you set a monthly cap and a billing alert there during the pre-flight check, you chose those amounts when the Tidy page was the only feature calling a model, so decide whether they still fit now that a second feature uses the account. If this feature uses a different provider, set both now.
  5. Try the feature on a preview copy. First, on the host's Environment Variables screen, make the new key available to both Preview and Production, and set the switch to true for Preview and false for Production. If you skip this, the preview copy fails the way the Tidy page did when its key was missing. Then ask the agent to push the change so that the host makes a preview copy, the private copy from Environments: why it works on your machine and breaks online, and tell it not to deploy to the live site. Open the preview link, run all five Proof Table inputs there, and read the host's log for errors. If the preview copy does not let you sign in, add the preview link to the addresses listed at your sign-in service, as you did for your domain name in Add accounts and member-only pages.

When all five inputs pass on the preview copy, you can let the change go to the live site with the switch off. Members see the support address where the chat box will be, and nothing they already use has changed. You decide whether to turn the switch on in the next chapter.

Adding an AI feature to a live site is a change to that site, so it gets the same checks as any other change. Read the diff, repeat the secrets and spending checks for the new key, and try the feature on a preview copy before any member can use it.

Fill in the Model Spec's last field

The decisions from this chapter go in the last field of the Model Spec, the one-page record of how your feature uses its model that you started in Choose the model you ship. (It is not OpenAI's Model Spec, a policy document about model behavior.) That field is called the fallback, and it holds the spend cap and what the feature does when the model is slow, unavailable, or wrong.

The Model SpecA one-screen Model Spec with seven fields: the job, the model, the prompt, the output, the context, the lever, and the fallback. It feeds the "Where AI fits" line of your Build Plan. Caption: one screen that records every decision this part walked you through.ONE FEATURE, ONE SCREENMODEL SPECthe run-time model, specifiedTHE JOBone feature, in one sentenceTHE MODELwhich one, which tier, and whyTHE PROMPTwhere it lives, and its rulesTHE OUTPUTthe structure, and the value checksTHE CONTEXTstuffed, retrieved, or noneTHE LEVERwhich rung you stopped atTHE FALLBACKcost cap, and what happens when it failsIt becomes the ‘Where AI fits’ line of your Build Plan.

The drawing shows the whole page: its seven fields, and a note that the finished page goes into the "Where AI fits" line of your Build Plan. After our hour, the fallback field on ours held four lines:

  • Route: the photo posts to /api/fridge-list; the server holds the key and makes the call.
  • Cap: monthly, at the provider console, set low enough that a runaway loop costs little.
  • Unreadable photo: the screen asks for a retake; the feature never guesses.
  • Timeout: items stream within seconds; at ten seconds, stop waiting and offer a retry.

On a live site, add a fifth line that names the switch and says how you turn the feature off. You finish the Model Spec in Launch your AI assistant with limits and a handoff to a person, where you add the assistant's limits to this same field.

Try it now

You spend nothing on the paper path, which takes about twenty-five minutes, and a few cents on the tooled path, which takes about an hour. You arrive with the last drill's result: your chosen model, a Proof Table of five real inputs, and a Model Spec with one field left. You leave with the feature wired into your site and tested on a preview copy: the call on the server, streaming on, the fallback written, the spend cap checked, the switch off on the live site, and the Model Spec's last field filled in.

No setup: Work through our session above on paper, from start to finish. Mark the line in our project file that says where the key is kept, and the words in our correction that named the symptom, the place, and the behavior we wanted. Then write the lines you would add to your own project file for your feature, and fill in the Model Spec's last field: where the call runs, the cap, what the feature does with input it cannot use, what your user sees after ten seconds, and how you turn the feature off. Last, write down, in order, the checks your change has to pass before it reaches your live site.

With your tools: Open Claude Code in the running-club folder, or in your own project, and make a save point. Add the lines for the AI feature to your project file, or create the file if your project has none, then paste your one-pager as the first message and give the ask. The running club's reads: "Add the support assistant from the one-pager as a chat box that signed-in members see. Send each question from our server to the model named in the config, with the prompt file exactly as written, the facts block, and the get_my_orders tool. Read the key from a new environment variable, ASSISTANT_API_KEY, and show the chat box only when ASSISTANT_ON is true, with the support address in its place when it is not. Do not change sign-in, payments, or any other page." Check the plan the agent prints against your one-pager before approving it. Verify both ways: run your first Proof Table input and read the diff, then correct once with specifics. Ask for the wiring: streaming, a ten-second timeout, and a fallback. The running club's fallback shows the support address, help@runclub.example, whenever a call fails or runs past the timeout. Then take the change through the checks for a live site, ending with all five Proof Table inputs on the preview link. Same move in Codex or Cursor: the project file is AGENTS.md, and the rest of the hour is the same. If nothing is installed, the Setup Clinic gets you running.

Either way, finish by adding these lines to the idea file. If you took the first path, write them as the plan for your own feature.

AI feature: support assistant, wired in, not launched
Secret:     ASSISTANT_API_KEY, in .env on my laptop,
            in Environment Variables on Vercel
            for Preview and Production
Switch:     ASSISTANT_ON, false on the live site
Cap:        monthly cap and billing alert checked
Tested:     5 of 5 Proof Table inputs on the preview copy

Chapter Summary

  • You can repeat the hour step by step: write the project file, paste the one-pager, give the ask, go once around the loop, add the wiring, and then take the change through the checks for a live site.
  • With ten lines in a CLAUDE.md-style file, covering what the app is, who it serves, the model's job, and what must never reach a user, the agent generates every plan from your constraints instead of generic defaults; other tools use a file named AGENTS.md the same way. When you make the same correction in more than one session, add it to the file.
  • The loop is describe, read the printed plan, verify, and correct. Verifying means both running a real input and reading the diff, and a good correction names the symptom, the place, and the behavior you want.
  • Code that runs is not the same as code that works: our draft passed the photo we ran while the API key sat pasted in the code, a flaw that running the feature would never show.
  • Rerun the Proof Table after every change, so you know a fix did not break something that already worked.
  • The wiring is four decisions: the call on the server with the key in an environment variable, streaming so the user sees progress during the wait, a fallback that asks for a retake instead of guessing, and a spend cap sized for the case where something goes wrong.
  • Because your site is already live, the change also goes through these checks: you read the whole diff, give the feature its own key and repeat the secrets check, add a switch that turns the feature off, check the spending cap, and run your Proof Table inputs on a preview copy. Then it goes to the live site with the switch off, so members see nothing new until you decide to launch.
  • You record these decisions in the last field of the Model Spec, the fallback.
  • Next, in Launch your AI assistant with limits and a handoff to a person, you decide whether to turn the feature on for real users, and you set its limits first.

Sources

  • Anthropic documentation for Claude Code project memory files, CLAUDE.md (last verified July 2026).
  • The AGENTS.md open convention documentation (last verified July 2026).
  • OpenAI, Model Spec, the model-behavior policy document distinguished from this course's Model Spec artifact (last verified July 2026).
  • OpenAI and Anthropic documentation for streaming responses and organization spend limits (last verified July 2026).
  • FuelTheFam (fuelthefam.com), our family nutrition app; the session dissected in this chapter wired the fridge feature that ships there.
  • Vercel documentation on environment variables: choosing Production, Preview, and Development for each variable, preview deployments, and changes applying only to new deployments (last verified November 2026).
  • Next.js documentation on environment variables and the NEXT_PUBLIC_ prefix (last verified November 2026).
  • Anthropic documentation on API keys, on disabling or deleting a key, and on setting a monthly spend limit (last verified November 2026).