On this page
Practice set · Block 1 · Week 2 · Building APIs and the backend
Building APIs
One chat app. One raw POST request. Proof against your golden pair.
The exercise in one sentence
Connect your Gradio app with a raw requests.post to an LLM, carrying your own prompt and your user's real input, and prove the reply is useful by checking it against your golden pair.
Which track are you on?
01Why This Exercise Exists
A passenger enjoys the comfort of a car. A driver understands its controls and knows what to do when things go wrong.
Comfort without understanding comes at the cost of control.
In software, SDKs, libraries, no-code/vibe-coding tools are like comfortable passenger seats. They make the journey easier by hiding the machinery underneath.
But hidden machinery doesn't disappear.
When something breaks, what you understand determines what you can fix.
To drive software machines, understand its controls: APIs, endpoints, authentication, requests, and responses.
Use abstractions for comfort. Build understanding for control.
A 200 proves the call worked. Only your verifier proves the reply helps.
02The Five Steps
Track B · Aarav as the user
Input: his weekly workflow. Output: a plan to automate part of it. Starting prompt:
"Here is the workflow of an analyst working at an IT company in India. Diagnose and generate a plan to automate this work, or a part of the work."
Target: the plan drifts into jargon Aarav cannot use.Step 1 · Where you start
Step 4 · The shape of the change
Each blank is one of the four parts, with the values from the raw request. Write it yourself.
03The Raw Request, Live
Step 2's request, sent from this page to Groq. Pick your predicted status code to unlock Send; every send goes to the prediction log. Your screenshot still comes from httpie.io/app.
Sent as Authorization: Bearer <key>. Held in this tab's memory only: never saved, gone when you reload. Get a key.
What status code do you expect?
The full reply package
What each code means here
| 200 | Groq understood you and sent a reply. It does not mean the reply helps anyone: that is section 05. |
| 400 | The package is wrong: broken JSON or a missing field. |
| 401 | The key is missing, mistyped, or sent without Bearer. |
| 404 | The model named in the package does not exist, or the address is wrong. Read the message: it says which. |
| 429 | Too many requests this minute on your account. Wait and send again. |
| 5xx | Their machine, not yours. Try again later. |
Status code says whose fault; the message says what. Try the fix the error points to before pasting anything into an LLM. More in Troubleshooting.
Got an error? Search it in Troubleshooting: the part it points to and the fix.
04Prediction Log
Three requests minimum, two of them deliberate failures. Sends from section 03 land here; add the rest by hand.
| Request | Predicted | Actual | Error message, for failures |
|---|
05Verify Against Your Golden Pair
Golden output beside the reply, a one-line verdict, one prompt change, run again.Load Aarav's golden pair below. The target is jargon.
06Rules of the Build
Predict before you run.
Every request in the prediction log gets its expected status code written down first. Include at least two deliberate failures: a wrong model name and a missing or wrong key. Record what each actually returned.
Read the error before you ask.
Status code says whose fault; the message says what. Try the fix the error points to before pasting anything into an LLM.
Minimum path.
No extra parameters, no chat history handling, no changed interface, no renamed functions. The diff from the echo app should be the process and nothing else.
Keys never in code or screenshots.
Set it in the terminal, never in the file. Blur the key in every image you share. If a key leaks, revoke it and create a new one: Keys.
Stay inside the free tier.
Groq allows 30 requests per minute. You will not need more.
LLM help: hints and debugging yes; generating the solution no.
Think for the first minute on your own. Pasting this brief in and copying the code out defeats the exercise; the code is short enough that writing it is the learning.
07Your Deliverables
The 201 question
08Stretch: Any Machine, Four Lines
- Pick one free API from the public-apis list (MediaStack is a fine start). Answer the four questions for it in writing before writing any code.
- Call it with
requestsand print one field from the JSON response. - Optional swap test: point your chat app at another OpenAI-compatible endpoint by changing only the URL, key and model name. Note what else, if anything, had to change.
09How to Get Unblocked
Search the exact error in Troubleshooting first. Then compare your file, line by line, with the shape in section 02 and the package on the wire in section 03. Keep your deliverables together: they are your proof that the system works and helps.
Next: building your own API, and how much protection it actually needs.
Hold this
A 200 means the machine understood you. It does not mean you helped anyone. Four lines get you to any machine on the internet; your golden pair tells you whether the trip was worth it for a human.
Four lines to any machine.Companion pages: Overview · The second interface · Groq step · troubleshooting · back to the roadmap