HTTP, REST APIs and JSON

Model providers are HTTP APIs; understand requests, headers, status codes, JSON bodies and how to build a small API of your own.

Beginner · about 10 hours · difficulty 2/5

Under every SDK call to a model is a plain HTTPS request with a JSON body and an API key header. When something breaks (a 429, a timeout, a malformed body) you debug at the HTTP level, so this layer needs to be familiar.

Core concepts

  • Methods and status codes: GET vs POST; 2xx success, 4xx your fault (400 bad request, 401 bad key, 429 rate limited), 5xx their fault (500, 503, overloaded).
  • Headers: Authorization or provider-specific key headers, Content-Type: application/json, and rate limit headers that tell you how much budget is left.
  • JSON: nested objects and arrays, escaping, and the difference between a JSON string and a parsed object.
  • Timeouts and retries: LLM calls can take many seconds. Set explicit timeouts and retry only on retryable errors (429, 5xx) with exponential backoff.
  • Server-Sent Events (SSE): the streaming format most model APIs use to send tokens as they are generated.

Building your own API

You will wrap model calls behind your own endpoint so that keys stay on the server. Learn one framework: FastAPI (Python) or Express/Hono (TypeScript). Understand request validation, returning errors with proper status codes, and CORS for browser clients.

Good enough to move on

You can call an API with curl and from code, read the status code and headers, and expose a POST endpoint of your own that validates input and returns JSON.

Key concepts

  • HTTP methods and status codes
  • Headers and authentication
  • JSON and JSON Schema basics
  • curl and API clients
  • Timeouts, retries and backoff
  • Server-Sent Events: How token streaming works
  • FastAPI
  • Express / Hono

Mini project

Build a FastAPI (or Express) service with one POST endpoint that validates a JSON body, calls a public API with a timeout and retries, and returns a clean JSON response or a meaningful error code.

Check yourself

Which HTTP status codes should your client retry automatically, and which should it never retry? Why?

Free resources