Idea 10 of 15 · The Claude API
Talking to Claude from code
Your code sends a list of messages and gets the next one back. Everything else is settings.
A request is a list of messages
A request names the model, caps the length of the reply and carries the conversation so far as a list of messages; Claude returns the next message. It also carries your API key, so send it from your server, never from a visitor’s browser.
The API is stateless
Claude keeps nothing between requests. To continue a conversation, your code sends every earlier message again, plus the new one. It’s the “one long document” from “How a chatbot writes”, and here your code holds it.
The system prompt sets the role
A system prompt sits outside the conversation and shapes every reply: who Claude is here, who it’s talking to and what the rules are. For the shop’s assistant: be brief, and never promise a refund, pass those to a person.
Temperature: steady or varied
Temperature sets how random each word choice is, as in “How a chatbot writes”. Near 0, a question gets nearly the same answer each time: good for precise work, like extracting data, classifying or writing code. Near 1, answers vary more: good for creative work, like naming, copywriting or brainstorming.
Streaming and a fixed shape
Long replies can stream: words arrive as they’re written, so nobody stares at a spinner. And when your code, not a person, reads the reply, use structured output to get JSON in an exact shape, so every answer can be read the same way.