Your first request explained
A line-by-line walkthrough of one Messages call — what every field does and what comes back.
The Quickstart gets you a response. This page explains what each part of it means, so the next request is one you write yourself.
The request
curl https://aiprimetech.io/v1/messages \
-H "x-api-key: $CLAUDEAPIKEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello"}]
}'
| Field | Required | What it does |
|---|---|---|
model | yes | Which model to run. Must match an id from /v1/models exactly. |
max_tokens | yes | Hard ceiling on the output. The model stops here even mid-sentence. This is a cost control, not a target. |
messages | yes | The conversation so far, oldest first. Each entry has a role (user or assistant) and content. |
system | no | Instructions that apply to the whole conversation. A top-level field, not a message with role: system. |
temperature | no | 0–1. Lower is more deterministic. Leave unset unless you have a reason. |
stream | no | true returns server-sent events instead of one JSON body. See Streaming. |
The response
{
"id": "msg_01ABC...",
"type": "message",
"role": "assistant",
"model": "claude-sonnet-4-6",
"content": [{"type": "text", "text": "Hello! How can I help?"}],
"stop_reason": "end_turn",
"usage": {"input_tokens": 9, "output_tokens": 12}
}
contentis an array, not a string. Text lives atcontent[0].text. Treating it as a string is the most common client bug.stop_reasontells you why generation ended:end_turn(finished),max_tokens(hit your ceiling — the reply is truncated),stop_sequence, ortool_use.usageis what you are billed on. Log it; it is the only reliable basis for cost attribution.
If
stop_reason is max_tokens, your answer was cut off. Raise max_tokens or ask for a shorter reply — do not retry blindly, you pay for the truncated output too.Multi-turn conversations
The API is stateless. To continue a conversation you resend the whole history, including the model's previous replies:
{
"model": "claude-sonnet-4-6",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "What is the capital of France?"},
{"role": "assistant", "content": "Paris."},
{"role": "user", "content": "And its population?"}
]
}
Because history is resent every turn, input tokens grow with the conversation and so does the bill. This is why long agent sessions get expensive. Prompt caching and context management both attack this directly.