How APIs work in AI-built applications
An API call is one program asking another for something over HTTP. Your app sends a request — a method, a URL, headers and sometimes a body — and gets back a status code and a response. Everything an AI-built app does beyond drawing pixels is some version of that exchange.
What is in a request?
| Part | What it is | Example |
|---|---|---|
| Method | The kind of action | GET to read, POST to create |
| URL | What you are acting on | /api/notes/42 |
| Headers | Metadata, including who you are | Authorization, Content-Type |
| Body | The data you are sending | { "title": "Hello" } |
The response comes back with a status code, headers of its own, and usually a body in JSON. The status code is the part people skip and the part that tells you most.
Which calls does a typical AI-built app make?
- Browser → your own server functions, for anything that needs a secret or a permission check.
- Your server → your database, to read and write rows.
- Your server → third-party services: payments, email, AI models, analytics.
- Browser → your database directly, when the service supports it and access rules do the protecting.
Knowing which of these four a broken feature uses narrows a mystery to one of four places before you read a single line of code.
How do you see the calls your app is making?
- 1Open your browser's developer tools and select the Network tab.
- 2Reload the page or trigger the broken action.
- 3Find the request that matters — filter by Fetch/XHR to hide images and fonts.
- 4Read its status code first, then its response body.
- 5Check the request headers: was an Authorization header actually sent?
This is the single highest-value skill on this page. Most 'the app is broken' reports resolve in under a minute once you have read the failing request.
What goes wrong most often?
| Symptom | Usual cause |
|---|---|
| 401 on every call | No credential sent, or the wrong one |
| 403 on some calls | Credential is valid but not allowed for this record |
| 404 on a call you expected to work | Wrong path, or the record genuinely does not exist |
| 429 under light use | Shared free-tier limit, or a loop calling repeatedly |
| 500 from your own endpoint | Your server code threw — read the server log, not the browser |
| CORS error | The browser blocked a cross-origin call your server should be making |
Why is the response body worth reading?
Good services explain themselves. A failed request usually returns a JSON body naming the exact problem: a missing scope, an invalid parameter, an expired token. Generated code often throws that body away and shows a generic 'Something went wrong', which turns a five-second fix into an afternoon.
if (!response.ok) {
const detail = await response.text();
console.error("Provider failed", response.status, detail);
throw new Error(`Provider failed [${response.status}]: ${detail}`);
}Frequently asked questions
- What is the difference between an API and a database query?
- A database query asks your data store directly. An API call asks a program, which may then query a database. Many hosted databases expose an API so the two blur together.
- Why does my call work in a testing tool but not in the app?
- Usually a missing header, a different key, or the browser adding origin restrictions the testing tool does not have.
- Should the browser call third-party APIs directly?
- Only if the service issues a publishable key for that purpose. Anything needing a secret key goes through your own server.
Practice this in MessyDev
Reading it once helps. Doing it once sticks. These are the hands-on parts of MessyDev that cover the same ground.
Keep going
- API keys explainedWhat an API key is, what it proves, why some keys are safe in a browser and others are not, and how to handle one without leaking it.
- 401 vs 403 vs 404 vs 429 vs 500Five status codes that cover most failures in an AI-built app, what each one is really saying, and who has to fix it.
- Why am I getting a 401 error?A 401 means the server could not identify you. The causes, how to tell which one you have, and how to confirm the fix.