Skip to main content
APIs9 min readPublished September 19, 2026Updated September 22, 2026

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?

PartWhat it isExample
MethodThe kind of actionGET to read, POST to create
URLWhat you are acting on/api/notes/42
HeadersMetadata, including who you areAuthorization, Content-Type
BodyThe 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?

  1. 1Open your browser's developer tools and select the Network tab.
  2. 2Reload the page or trigger the broken action.
  3. 3Find the request that matters — filter by Fetch/XHR to hide images and fonts.
  4. 4Read its status code first, then its response body.
  5. 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?

SymptomUsual cause
401 on every callNo credential sent, or the wrong one
403 on some callsCredential is valid but not allowed for this record
404 on a call you expected to workWrong path, or the record genuinely does not exist
429 under light useShared free-tier limit, or a loop calling repeatedly
500 from your own endpointYour server code threw — read the server log, not the browser
CORS errorThe 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.

Keep the provider's own error text
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