HASZB_AIHASZB_AI

Search across courses, lessons, glossary terms, prompts and tools.

Lab 08

API Explorer

Under every AI product is an HTTP request with a body and a response with a shape. Once you can read one, the rest are variations.

Conceptual model. Nothing here is sent anywhere. The endpoint is a placeholder, the key is the literal textYOUR_API_KEY, and the response below is an illustrative shape rather than a captured reply.

Build the request

The round trip

  1. Your app
  2. HTTP requestPOST + JSON body
  3. Provider API
  4. HTTP responseJSON + usage
  5. Your app
POST /v1/messages
{
  "model": "a-model-id",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": "Explain what a token is, in one sentence."
    }
  ]
}

The body is ordinary JSON. There is nothing AI-specific about the transport.

Reading the result

What just happened
The form above assembles a request body. Change the prompt or the token ceiling and watch the JSON — and every code sample — change with it.
Why it matters
Once you can read this shape you can read any provider's docs. The differences between them are mostly field names, not concepts.
Where you meet this
This is the request behind every AI feature you have used. Theusage block in the response is what your bill is calculated from.

Never do this

  • Key in frontend code. Anything the browser can read, a visitor can read. Proxy through your own server.
  • Key in the URL. URLs are logged by servers, proxies and browsers. Keys belong in a header.
  • Key committed to git. History is forever; rotating the key is the only real fix.