Basic Prompt Structure
Learn the fundamentals of the Claude API
The Messages API
Anthropic offers two APIs: the legacy Text Completions API and the current Messages API. This tutorial uses exclusively the Messages API.
At minimum, a call to Claude requires the following parameters:
model— the API model name of the model you intend to callmax_tokens— the maximum number of tokens to generate before stopping. Note that Claude may stop before reaching this maximum. This is a hard stop, meaning it may cause Claude to stop mid-word or mid-sentence.messages— an array of input messages. Claude is trained to operate on alternatinguserandassistantconversational turns. Each input message must be an object with aroleandcontent.
There are also optional parameters:
system— the system prompt (more below)temperature— the degree of variability in Claude's response. For these lessons we usetemperature: 0.
Message Structure & Rules
Every message needs a role and content field:
[
{ "role": "user", "content": "Hi Claude!" },
{ "role": "assistant", "content": "Hello! How can I help?" },
{ "role": "user", "content": "What's the capital of France?" }
]
Two rules the API enforces:
- Messages must alternate between
userandassistantroles - The first message must always be a
userturn
Violating either rule returns an API error.
System Prompts
A system prompt lives in a separate system parameter — not inside the messages array. It lets you provide context, instructions, and guidelines to Claude before the conversation begins.
SYSTEM: "You are a helpful assistant who only responds in rhymes."
USER: "What's the weather like today?"
CLAUDE: "The weather today is bright and clear,
with sunshine and warmth throughout the year!"
A well-written system prompt can dramatically improve Claude's performance — it increases Claude's ability to follow rules and stay consistent throughout a conversation.
Key Insight
Think of Claude as a capable new colleague who has zero context beyond what you explicitly tell them. Nothing is assumed. Everything must be spelled out — in either the system prompt, the user message, or both.