Messages
MarkdownThe Anthropic Messages format. Used by Claude Code, the Anthropic SDK, and many agents.
Full guide
https://api.ailoot.ai/v1/messagescurl https://api.ailoot.ai/v1/messages \
-H "x-api-key: $AILOOT_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello! What can you do?"}]
}' import anthropic
import os
client = anthropic.Anthropic(max_retries=0,
base_url="https://api.ailoot.ai", # without /v1: the SDK adds /v1/messages itself
api_key=os.environ["AILOOT_API_KEY"],
)
msg = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Explain what an API is in two sentences."}],
)
print(msg.content[0].text)import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({ maxRetries: 0,
baseURL: "https://api.ailoot.ai", // without /v1
apiKey: process.env.AILOOT_API_KEY,
});
const msg = await client.messages.create({
model: "claude-sonnet-5-5",
max_tokens: 1024,
messages: [{ role: "user", content: "Explain what an API is in two sentences." }],
});
console.log(msg.content[0].type === "text" ? msg.content[0].text : msg.content);{
"id": "msg_01H…",
"type": "message",
"role": "assistant",
"model": "claude-sonnet-5-5",
"content": [
{ "type": "text", "text": "Hello! I can write and explain code, answer questions…" }
],
"stop_reason": "end_turn",
"usage": { "input_tokens": 14, "output_tokens": 52 }
}Authentication
- x-api-keyheaderrequired
Key
sk-…. You can also useAuthorization: Bearer sk-…— this is what Claude Code uses withANTHROPIC_AUTH_TOKEN. - anthropic-versionheaderoptional
API version, for example
2023-06-01. SDKs send it automatically.
Request body
- modelstringrequired
Model ID that supports the Messages format — 776 IDs: Claude, as well as GPT, Gemini, DeepSeek, Qwen, and others.
- messagesarrayrequired
Messages
userandassistant;content— a string or blocks (text,image,tool_use,tool_result). - max_tokensintegerrequired
Maximum number of response tokens. Included in the reserve; if your balance is too low for the full limit, Ailoot reduces it, but never below 256 (1025 with thinking enabled), and reports the new limit in the header
X-Ailoot-Max-Tokens-Capped. - systemstring | arrayoptional
System instruction.
- streambooleanoptional
SSE event stream (
message_start,content_block_delta, …,message_stop). Billable text is delivered in a single block after the cost is calculated. - temperaturenumberoptional
Response randomness, from 0 to 1.
- toolsarrayoptional
Tools:
name,description,input_schema. - tool_choiceobjectoptional
auto,any,toolornone. - thinkingobjectoptional
{"type": "enabled", "budget_tokens": N}— thinking for models that support it. - stop_sequencesarrayoptional
Strings that stop generation.
Response
- contentarray
Response blocks:
text,thinking,tool_use. - stop_reasonstring
end_turn,max_tokens,stop_sequenceortool_use. - usageobject
input_tokens,output_tokens, for caching —cache_read_input_tokensandcache_creation_input_tokens.