Messages API: Required Parameters
Every Claude call via the Messages API requires three parameters:
- model — the model name (e.g.,
claude-opus-4-5)
- max_tokens — hard limit on response tokens
- messages — an array of objects with
role and content fields
Roles must alternate, and the array must always start with user.
PROMPT = "Hi Claude, how are you?"
# → correct: {"role": "user", "content": PROMPT}
# Error — two user messages in a row:
messages=[
{"role": "user", "content": "Celine Dion birth year?"},
{"role": "user", "content": "Tell me more about her."}
]
# API will return 400 error
System Prompt
The system prompt sets context before the first user message:
SYSTEM_PROMPT = "Your answer should always be a series of critical thinking questions that further the conversation (do not provide answers). Do not actually answer the user question."
PROMPT = "Why is the sky blue?"
# Claude responds with questions, not an explanation
Why This Matters
The system prompt is your primary tool for controlling Claude's behavior. It sets the role, tone, constraints, and output format before the user writes a word.
When to Use Prefill
In the last assistant message, you can start the response for Claude — it will continue from that point:
messages=[
{"role": "user", "content": "List three fruits."},
{"role": "assistant", "content": "1."} # Claude continues: " Apple
2. Banana
3. Cherry"
]