AI Income LabJoin AI Income Lab ↗

Build guide · By · Published · Updated

Codex tutorial: make and verify a small code change

Quick answer

Give Codex a narrow brief for one change, inspect the diff it proposes, then run a check that proves the change works. In this exercise you add a malformed-JSON request to a local API example and assert that it returns HTTP 400. You need Git, Node.js 22 or later and a configured coding assistant, but no provider key.

This Codex tutorial takes one small task from a brief to a checked diff: add a malformed-JSON check to this site’s local API example. You will finish with a script that verifies a failure case as well as the existing successful request.

Bring Git, Node.js 22 or later, and a configured coding assistant. The exercise makes only local requests and needs no provider key. Your coding assistant may have its own usage charges. No Skool membership is needed to read or run it.

Diagram: make a small change you can verify in three steps: write a narrow brief, inspect the diff, run the check.
Write a narrow brief, inspect the proposed diff, and run a check.

1. Start from a working example

mkdir api-check && cd api-check
git init
curl -O https://www.ai-automation-station.com/examples/first-api-request.mjs
git add first-api-request.mjs
git commit -m "Add the baseline example"
git switch -c practice/api-json-check
node first-api-request.mjs

No npm install is needed for this example. It uses Node’s built-in modules, starts a server on loopback, checks three requests, and closes it. Read the API request guide if keys, models, and status codes are new to you.

The baseline prints HTTP 401 for the wrong key, HTTP 404 for an unknown model, HTTP 200 for a valid request, and a PASS line. Save this output before changing anything. If it fails already, resolve that failure first.

2. Give Codex a concrete brief

Include the goal and constraints

Open the cloned folder in your coding client. Ask it to inspect public/examples/first-api-request.mjs, then use this brief:

Add one executable check for malformed JSON to this local example.
Send an incomplete JSON body with the valid demo key.
Assert HTTP 400 and the existing "Invalid JSON" error.
Keep the three existing checks, timeout, redirect handling, and cleanup.
Use only built-in Node modules. Do not connect a real provider.
Run the example and show the diff and output. Do not commit or push.

This is an author-written practice task using the example script, separate from the recorded Codex internal-link audit. Both use the same useful sequence: inspect, change, check, and review. The exact client buttons and model names are not part of the exercise. To see how I split work between Codex and Claude Code, read Claude Code vs Codex. If a run stops with a usage-limit message, check remaining allowance and reset times in Codex usage limits.

3. Check the proposed change

The server already catches invalid JSON and replies with status 400. The missing piece is a request that exercises that branch. A minimal addition inside the existing try block, after the request loop and before the PASS message, can look like this:

const malformed = await fetch(endpoint, {
  method: 'POST',
  redirect: 'error',
  signal: AbortSignal.timeout(5000),
  headers: {
    'Content-Type': 'application/json',
    Authorization: 'Bearer demo-only',
  },
  body: '{',
});
assert.equal(malformed.status, 400);
assert.deepEqual(await malformed.json(), { error: 'Invalid JSON' });
console.log('Malformed JSON: HTTP 400');

Use the valid demo key so the request reaches JSON parsing. A wrong key would test authentication again. Keep the request inside the try block so the existing finally still closes the server on failure.

4. Run it and inspect the diff

node public/examples/first-api-request.mjs
git diff --check
git diff -- public/examples/first-api-request.mjs
git status --short

Expect the original three status lines, then Malformed JSON: HTTP 400, then PASS. Check that only your intended file changed. A passing script is evidence for these four checks; it doesn't prove a real provider connection or replace a comprehensive security review.

When the result is wrong

Continue with a real project

To work on a site after this local exercise, apply that review loop to an internal-link audit. The case separates the audit evidence, proposed changes and checks before publication.

The source example is first-api-request.mjs. Then try the React YouTube-feed build. If you will run Codex every day, compare what each plan includes in ChatGPT Pro 20x vs 5x vs Plus. The OpenCode desktop build shows why launching an app and checking saved data matter even after compilation passes.

When you want to organize terminal sessions around a project, the Herdr Desktop workspace guide shows agent panes, themes and migration limits. The workspace interface complements this review loop, while each agent still needs its own installation and account access.

FAQ

What do I need for this Codex tutorial?

Git, Node.js 22 or later and a configured coding assistant. The exercise makes only local requests, so no provider key is needed, although your coding assistant may have its own usage charges.

What should the Codex brief include?

One goal and its constraints: send an incomplete JSON body with the valid demo key, assert HTTP 400 and the existing “Invalid JSON” error, keep the existing checks and cleanup, use only built-in Node modules, and do not commit or push.

Why does the malformed request use the valid demo key?

So the request reaches JSON parsing. A wrong key would only test authentication again and return 401 instead of 400.

Does a passing script prove the change is safe?

It is evidence for the four checks in the script. It doesn't prove a real provider connection or replace a full security review, so still inspect the diff and confirm that only the intended file changed.

Sources

You may also like

Written by . I’ve shipped software since 2013 and test AI tools on real builds for the AI Automation Station YouTube channel. Each guide shows the date it was last updated and lists the sources it relies on.

Build the next one with AI Income Lab

Step-by-step courses, reusable templates, and a community that answers when you get stuck.

Members get the Claude Code & Skills and Codex Tutorials & Courses lessons.

Join AI Income Lab ↗From $29/month. Cancel anytime.
Join 2,900+ members building with AI

Not ready to join? Get the weekly build notes: new guides and tested builds in one short email.