POST
/
v1
/
messages
curl -X POST https://api.example.com/v1/messages \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "model": "claude-haiku-4-5-20251001",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": "Hello, Claude!"
      }
    ]
  }'
{
  "id": "msg_01XFDUDYJgAACzvnptvVoYEL",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "Hello! How can I help you today?"
    }
  ],
  "model": "claude-haiku-4-5-20251001",
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 10,
    "output_tokens": 12
  }
}
Official documentation: https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking
Create model responses for given messages using Anthropic Claude models.

Request Parameters

model
string
required
The model to use. Available models include:
  • claude-haiku-4-5-20251001
  • claude-sonnet-4-20250514
  • claude-opus-4-5-20251101
max_tokens
integer
required
The maximum number of tokens to generate before stopping.
messages
array
required
Input messages. Each message has a role and content.content can be:
  • A string for simple text messages
  • An array of content blocks for multimodal input (text, images, documents)
temperature
number
default:"1"
Amount of randomness injected into the response. Ranges from 0.0 to 1.0.
top_p
number
Use nucleus sampling. Only sample from the top P probability mass.
top_k
integer
Only sample from the top K options for each subsequent token.
stream
boolean
default:"false"
Whether to incrementally stream the response using server-sent events.
system
string
System prompt that sets context and instructions for the model.

Multimodal Content

Claude supports various content types in messages:

Text Content

{
  "type": "text",
  "text": "Your message here"
}

Image Content

{
  "type": "image",
  "source": {
    "type": "base64",
    "media_type": "image/jpeg",
    "data": "base64_encoded_image_data"
  }
}

Document Content (PDF)

{
  "type": "document",
  "source": {
    "type": "base64",
    "media_type": "application/pdf",
    "data": "base64_encoded_pdf_data"
  },
  "cache_control": {
    "type": "ephemeral"
  }
}

Response

id
string
Unique identifier for the message.
type
string
Object type, which is message.
role
string
Role of the generated message, which is assistant.
content
array
Content generated by the model.
model
string
The model that processed the request.
stop_reason
string
The reason the model stopped generating.
usage
object
Token usage information.
curl -X POST https://api.example.com/v1/messages \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "model": "claude-haiku-4-5-20251001",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": "Hello, Claude!"
      }
    ]
  }'
{
  "id": "msg_01XFDUDYJgAACzvnptvVoYEL",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "Hello! How can I help you today?"
    }
  ],
  "model": "claude-haiku-4-5-20251001",
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 10,
    "output_tokens": 12
  }
}