Index Ai Academy
Phase 0 · ToolsTalking to APIs

Your first LLM call

About 30 minLooking ahead: some prerequisites aren't done yet

Why this matters

Every AI product you've used, from chat apps to writing assistants to agents, is built on the request you're about to send. The chat window is a website making this exact HTTP call for you. Once you can make it yourself, you can put a model inside any script, spreadsheet export or workflow. Everything in Phase 1 builds on this one call.

  • Send a request to a model with a system prompt and a user message
  • Pull the reply text out of the response, whatever blocks it contains
  • Check stop_reason and token usage before trusting a reply
  • Continue a conversation by sending the whole history

An LLM is an API

You already know every piece of this. Think of it as filling in an order form and posting it: the envelope says who it's from and where it goes, and the form inside says what you want. Calling Claude is a POST request with three headers (the envelope) and a JSON body (the form):

POST https://api.anthropic.com/v1/messages

x-api-key: <your API key>
anthropic-version: 2026-10-21
content-type: application/json
{
  "model": "claude-opus-5-5",
  "max_tokens": 1000,
  "system": "You write email subject lines for an outdoor clothing brand.",
  "messages": [
    {"role": "user", "content": "Write one subject line for our spring sale."}
  ]
}

The headers carry your key (x-api-key), the version of the API your code was written for (anthropic-version), and the body's format. The body says which model to use and what to send it.

Note: In the academy, requests to api.anthropic.com go through the academy's own server, which attaches the real API key. So the x-api-key your code sends is replaced. If the academy has no key set up, you get a clearly labeled simulated reply with the same shape as a real one. On your own computer, you'd read your key from an environment variable, exactly as in the last lesson.

The request body

FieldRequiredWhat it does
modelyesWhich model answers. claude-opus-5-5 is Anthropic's main model; smaller ones are faster and cheaper (Phase 1 covers choosing).
max_tokensyesThe most the reply may contain, in tokens. If the model reaches it, the reply is cut off.
messagesyesThe conversation so far: a list of {"role": ..., "content": ...} dictionaries.
systemnoStanding instructions: who the model is, what it's for, rules to follow.

A token is the unit models read and write: a word or a piece of a word. In English, one token is roughly four characters, so 1,000 tokens is about 750 words. Providers measure limits and prices in tokens.

Roles. Each message has a role: "user" for what you (or your app's user) say, and "assistant" for what the model said earlier. The list must start with a user message. Instructions for the whole conversation go in system, not in the messages.

Note: Older tutorials also set temperature in the body. The current API version (2026-10-21) no longer accepts it, and returns an error. Phase 5 explains what temperature does inside a model.

Build a request below and send it. The panel shows the JSON body and the matching Python.