Python, from Zero, for AILesson 50 of 89

Module 6 · Talking to a service: HTTP from Python, done properly

What a request is made of, and how to see the one you actually sent

In this lesson

  • 8 min read
  • 7 reading sections
  • Knowledge check
  • Lesson 2 of 11 in this chapter

This chapter’s goalWrite a client for a paid model API that reuses connections, times out, retries only what is safe to retry, walks pagination with a generator, consumes a streamed response as it arrives, runs many requests concurrently under a rate limit, validates the JSON the model returns before trusting it, and reports the cost of every call from the usage figures in the response.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmWatch2:28Not available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 9Free · no account needed
Lesson steps

Four parts, every time

Every HTTP request your program sends has the same four parts, and requests builds all of them from the arguments you pass. When a call misbehaves, the fault is in one of these four, and knowing which one is most of the diagnosis.

  1. The method. GET asks for something; POST sends something; PUT, PATCH and DELETE change or remove. Model APIs are almost entirely POST, because the prompt travels in the body.
  2. The URL, including the query string. Everything after ? is a set of key=value pairs separated by &.
  3. The headers. Key-value metadata: who you are, what format you are sending, what format you will accept.
  4. The body. Optional. Bytes, usually JSON text, sent with POST.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Stuck on something?Ask Divya, your AI tutor

How to cite: Addaly (2026) ‘What a request is made of, and how to see the one you actually sent’, in Python, from Zero, for AI. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/python-for-ai/anatomy-of-a-request (Accessed: 21 November 2026).