By the end of this lesson you will call a real API yourself, read its answer like a row in a sheet, and know what each common status code is telling you to do.
You need: a browser; a terminal is optional (see open a terminal) · Time: 8 minutes
Think of a chai stall. You don't walk into the kitchen and make your own chai. You tell the person at the counter "one cutting chai", and a cup comes back. You never see how it was made.
An API (Application Programming Interface) is that counter, for programs. One program asks, another program answers, and there are fixed rules for how to ask.
- The client is the program that asks: your app, your browser, or a command in the terminal.
- The server is the computer that answers. It holds the data and the rules.
You use APIs all day without seeing them. A UPI app asks your bank's server "is there ₹200 in this account?". A weather app asks a weather server "what is the temperature in Pune?". When your coding agent talks to an AI model through AllModelAPI, it is calling an API too.
Why?Almost every app you will build is a client talking to one or more servers. When something breaks, the first question is always "what did we ask, and what came back?". This lesson teaches you to answer it.
Let's ask a real server a real question: which post offices are in pincode 110001 (central New Delhi)? This is a free API that needs no key or sign-up.
- Open this address in Chrome, Edge or Firefox: https://api.postalpincode.in/pincode/110001
- You will see a wall of text with curly brackets. That is JSON, the format most APIs answer in.
- In Chrome or Edge, tick Pretty-print at the top to see it neatly indented. Firefox shows it as a tidy tree on its own.
Now do the same from the terminal with curl, a small program that sends a request and prints the answer. It comes with macOS, Linux and Windows 10/11. The
-ioption also prints the status line and headers.Terminal · macOS / Linuxcurl -i https://api.postalpincode.in/pincode/110001PowerShell · Windowscurl.exe -i https://api.postalpincode.in/pincode/110001This is what came back when we ran it on 19 November 2026 (shortened):
Do it now Do it now
Why?You just made an API call with no app and no code. The browser, curl and your future app all send the same kind of request. When your agent's code fails, you can now test the API on its own and see whether the problem is the API or the code.
Every request has up to four parts. Think of sending a courier:
- Method: what you want to do.
GET= read something.POST= send something new (a form, a payment, a message).PATCH= change part of something.DELETE= remove it. - URL: the address.
https://api.postalpincode.inis the base URL (the shop),/pincode/110001is the path (which counter, which item). Some APIs take extra options after a?, like?city=Pune&days=3; these are called query parameters. - Headers: labels on the envelope.
Content-Type: application/jsonsays "the letter inside is JSON".Authorization: Bearer YOUR_API_KEYsays "here is my key". - Body: the letter inside. A
GETusually has none. APOSTcarries the data, for example a new student's name and phone.
The response comes back with a status code (a three-digit number saying how it went), its own headers, and usually a body in JSON.
One request goes out, one response comes back. Every API call has this shape. Why?When you ask your agent "which API call failed?", it will answer in these words: method, URL, headers, body, status. Knowing them lets you check its answer instead of nodding along.
- Method: what you want to do.
JSON looks scary but it is just a sheet written as text:
{ }holds one record, like one row. Inside, each"key": valuepair is a column name and the cell value.[ ]holds a list, like many rows.- Text is in
"quotes", numbers are not,true/falseare yes/no, andnullmeans an empty cell.
Keys become column headers, values become cells, null is an empty cell. Now read the pincode answer again. The outside
[ ]is a list with one item. That item hasMessage,StatusandPostOffice. AndPostOfficeis itself a list of 21 records: 21 rows, one per post office, each with the same columns.TipLong JSON? Paste it into your agent and ask: "Show this JSON as a table with one row per post office. Do not invent any fields." The last sentence matters: agents sometimes add fields that are not in the data.
Why?Agents often guess field names (
pincodeinstead ofPincode,nameinstead ofName). JSON is case-sensitive, so one wrong letter means an empty screen. Reading the real JSON yourself is how you catch it.The status code is the first thing to check when something goes wrong. The first digit tells you whose problem it is: 2xx worked, 4xx something is wrong with the request (your side), 5xx something broke on the server (their side).
Code Meaning What you do 200 OK It worked. Read the body. 201 Created It worked and something new was saved. Usually after a POST; the body often has the new item's id. 400 Bad Request The server could not understand the request. Check the URL, parameters and body for a typo or wrong format. 401 Unauthorized You did not prove who you are. The key or login is missing, wrong or expired. 403 Forbidden The server knows who you are and still says no. You lack permission. A new key won't help; ask for access. 404 Not Found Nothing at that address. Check the path and the id. 429 Too Many Requests You asked too often. Wait and slow down. Don't retry in a tight loop. 500 Internal Server Error The server crashed on its side. Not your typo. Try again later; if it is your own server, read its logs. CarefulNot every API follows the rules. This pincode API answers 200 even for a pincode that does not exist, and puts
"Status":"Error"inside the body. Always check the status code and what the docs say an error looks like.Match them Match each status code with what it tells you to do
Tap an item on the left, then its meaning on the right.
Why?"It's not working" gets you nowhere with an agent. "The call to /pincode returns 429" points straight at the fix. The code turns a vague bug into a specific one.
Many APIs need an API key: a long secret text that says "this request comes from me, bill me". It travels in a header, usually like this:
TextAuthorization: Bearer YOUR_API_KEYTwo rules, no exceptions:
- Keys live only on a server: in a
.envfile on your laptop or in your hosting settings. Never in browser code, never in GitHub, never in a screenshot or a chat. - Every key gets a spend limit, so a leak costs a little, not a lot. On AllModelAPI you set one per key on the API keys page.
Anything in browser code can be read by anyone who opens your site. How to keep keys safe, and what to do if one leaks, is covered in Keep secrets secret.
Why?A key is like your UPI PIN for an API. Whoever has it can spend your money. Knowing where it must live lets you catch an agent that puts it in the wrong place.
- Keys live only on a server: in a
- An API is a counter between programs: a client sends a request, a server sends a response.
- A request has a method, a URL, headers and sometimes a body; a response has a status code, headers and a body.
- JSON is a sheet as text:
{ }is one row,[ ]is many rows, keys are column names. - 2xx worked, 4xx fix your request, 5xx it broke on their side; and some APIs hide errors inside a 200.
- API keys go in a header, live only on a server, and get a spend limit.
- Next: build a Pincode finder that calls a public API.
Create a free account to save your progress and open every lesson. Create free account