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
- Your app
- HTTP requestPOST + JSON body
- Provider API
- HTTP responseJSON + usage
- Your app
{
"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. The
usageblock 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.