Home / Docs / Messages API

Messages API

POST /v1/messages — the Anthropic-format endpoint: parameters, response shape and examples.

The endpoint every Anthropic-compatible client uses, including Claude Code and the official SDKs.

EndpointPOST https://aiprimetech.io/v1/messages
Authx-api-key: sk-...
Version headeranthropic-version: 2023-06-01
Content typeapplication/json

Request body

FieldTypeRequiredDescription
modelstringyesModel id, exactly as listed by /v1/models
messagesarrayyesAlternating user / assistant turns, oldest first
max_tokensintegeryesMaximum output tokens. Generation stops here.
systemstring or arraynoTop-level system prompt. Not a message role.
temperaturenumberno0–1. Omit for the model default.
top_pnumbernoNucleus sampling. Use this or temperature, not both.
stop_sequencesarraynoStrings that halt generation when produced
streambooleannotrue for server-sent events
toolsarraynoTool definitions — see Tool use
metadataobjectnoPassed through; user_id is useful for your own attribution

Example

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"}]
  }'

Response

{
  "id": "msg_01ABC...",
  "type": "message",
  "role": "assistant",
  "model": "claude-sonnet-4-6",
  "content": [{"type": "text", "text": "..."}],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {"input_tokens": 9, "output_tokens": 12}
}
FieldDescription
contentArray of blocks. Text blocks carry type: text and a text field; tool calls carry type: tool_use.
stop_reasonend_turn, max_tokens, stop_sequence or tool_use
usage.input_tokensBilled input, including the full resent history
usage.output_tokensBilled output — typically 4–5× the input rate

System prompts

{
  "model": "claude-sonnet-4-6",
  "max_tokens": 1024,
  "system": "You are a terse assistant. Answer in at most two sentences.",
  "messages": [{"role": "user", "content": "Explain HTTP caching."}]
}
A stable system block is the ideal target for prompt caching — it is identical on every call, so it can be read from cache at a fraction of the input price.

Multimodal input

Image blocks use the standard Anthropic shape — see Vision.