← The complete build

BUILD 01 / LESSON 03 OF 06

Add an AI draft you can verify

Connect a server-side AI key, request structured output, and verify the draft against the original enquiry.

Download source kit ↓

Run the app on a computer with Node.js 22.22+.

OPEN THESE FILES

model.mjs · .env.example

Keep a useful app when AI is unavailable.

The inbox already works without a model. Prepare rules draft takes an excerpt and adds a fixed follow-up question. It is labelled as rules, because no AI was called. The separate Request AI draft button becomes available only when the server has a key.

To try actual AI, put your own OPENAI_API_KEY in .env and restart Node. Requests use your provider account and may incur charges. Review current model access and pricing first. Only the message text is sent; names or emails typed inside that message would travel with it.

Give the output a shape.

The reference uses the Responses API and a strict schema for a summary, missing-information questions, and a verbatim evidence excerpt. It uses a documented GPT-4.1 mini snapshot that can be changed through OPENAI_MODEL. Read generateSummary and parseSummary in model.mjs.

OPENAI_API_KEY=your_private_key_here
OPENAI_MODEL=gpt-4.1-mini-2025-04-14

These are environment settings, not browser code. Do not paste an actual key into a lesson, screenshot, repository, or shared chat. The API response must be complete and contain a valid draft. A refusal, incomplete response, malformed JSON, or evidence excerpt absent from the original produces an error.

Shape is not truth.

Test an enquiry with no budget or deadline. A useful summary preserves those unknowns. The evidence check verifies an exact excerpt, but it cannot prove every claim in the summary. The original message remains visible for a person to compare.

The request has a 20-second timeout and an output cap. AI attempts are limited to six per minute within this one server process. None of those controls is a guaranteed dollar budget. The source kit’s AI requests are fixture-tested; this release was not tested against a live provider because no key was connected.

Read the official Structured Outputs guide, model documentation, and current pricing before enabling it.

CHECK YOUR UNDERSTANDING / LESSON 03

Can you explain the choice?

A draft passes the JSON schema but invents a budget. What should you do?

Now prove it in your app.

Check these only after doing the work. The page cannot inspect your local app.

Pass the concept check and confirm all three hands-on checks to save your progress.