promptdojo_

GET, status, JSON — the call AI makes 100 times a day — step 1 of 9

The shape of an API call

Every AI-generated script that talks to a service does roughly this:

import httpx

response = httpx.get("https://api.example.com/users/7")
response.raise_for_status()        # crash on 4xx/5xx
data = response.json()              # parse the body as JSON
print(data["name"])

Four lines. AI writes them on autopilot. Your job is to read them and catch the two places it breaks: forgetting the status check, and indexing into the JSON with the wrong key.

A note on this chapter: the browser can't make real network calls. So instead of hitting a real URL, we'll work with hardcoded JSON shapes that match what an API would actually return. The pattern is the same; we just skip the wire.

Run the editor. We'll start by reading from a fake response.

read, then continue.