Endpoint: POST /messages
Send a message to Claude via the Messages API.
Most integrations should use Create Chat Completion. Use this endpoint when you specifically need Anthropic’s Messages request format.
import os
import requests
response = requests.post(
"https://api.yourouter.ai/v1/messages",
headers={
"Authorization": f"Bearer {os.environ['YOUROUTER_API_KEY']}",
"Content-Type": "application/json",
"anthropic-version": "2023-06-01",
"vendor": "anthropic"
},
json={
"model": "claude-3-5-sonnet-20240620",
"messages": [{"role": "user", "content": "Hello"}]
}
)
print(response.json())
Parameters
Conversation history in Claude’s message format.
If true, results are returned as server-sent events.
For Claude vision models, send image content blocks in the messages array.
curl https://api.yourouter.ai/v1/messages \
-H "Authorization: Bearer $YOUROUTER_API_KEY" \
-H "Content-Type: application/json" \
-H "anthropic-version: 2023-06-01" \
-H "vendor: anthropic" \
-d '{
"model": "claude-sonnet-4-20250514",
"max_tokens": 300,
"messages": [
{
"role": "user",
"content": [
{ "type": "text", "text": "Describe this image in one sentence." },
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/jpeg",
"data": "<BASE64_IMAGE>"
}
}
]
}
]
}'
For Claude models that support PDFs, send a document content block and set source.media_type to application/pdf. The data field contains the base64-encoded raw PDF bytes.
curl https://api.yourouter.ai/v1/messages \
-H "Authorization: Bearer $YOUROUTER_API_KEY" \
-H "Content-Type: application/json" \
-H "anthropic-version: 2023-06-01" \
-H "vendor: anthropic" \
-d '{
"model": "claude-sonnet-4-20250514",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": [
{
"type": "document",
"source": {
"type": "base64",
"media_type": "application/pdf",
"data": "<BASE64_PDF>"
}
},
{
"type": "text",
"text": "Summarize this PDF and list risks to watch."
}
]
}
]
}'
Claude PDF support depends on the specific model. Use standard, unencrypted PDFs and control request body size and page count; split large documents into batches.
See the Multimodal guide for the broader integration path.