Anthropic Messages
POST /v1/messages accepts Anthropic’s native request shape and returns an
Anthropic-shaped response. LLM API translates the request to the selected
provider and translates the result back to Anthropic’s format, so existing
Anthropic SDK clients can usually change only their base URL and key. It
supports streaming with stream: true.
Supported models
This endpoint currently supports Claude-family models (including Claude on Bedrock) and DeepSeek
models with an Anthropic-compatible surface. Use /v1/chat/completions for other models.
Quick start
curl -X POST "https://api.llmapi.ai/v1/messages" \
-H "Authorization: Bearer $LLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"max_tokens": 256,
"messages": [{"role": "user", "content": "Summarize the gateway flow."}]
}'
The response follows Anthropic’s message shape. Read text from the returned
content blocks rather than assuming a single string:
{
"id": "msg_abc123",
"type": "message",
"role": "assistant",
"model": "claude-sonnet-4-6",
"content": [{ "type": "text", "text": "LLM API routes..." }],
"stop_reason": "end_turn",
"usage": { "input_tokens": 18, "output_tokens": 12 }
}
Request shape
| Field |
Description |
model |
Claude-family or compatible DeepSeek model ID. |
messages |
Conversation messages. Text can be a string or an array of Anthropic content blocks. |
max_tokens |
Required output-token ceiling for a normal Messages request. |
system |
Optional system instruction, as a string or content blocks. |
temperature, top_p, stop_sequences |
Sampling and stop controls supported by the selected model. |
tools, tool_choice |
Anthropic tool definitions and selection controls where supported. |
stream |
Return Anthropic SSE events instead of one JSON response. |
cache_control |
Anthropic prompt caching, top level or on blocks; see prompt caching. |
For multimodal Claude models, use Anthropic content blocks. For example:
{
"model": "claude-sonnet-4-6",
"max_tokens": 256,
"messages": [
{
"role": "user",
"content": [
{
"type": "image",
"source": {
"type": "url",
"url": "https://example.com/photo.jpg"
}
},
{ "type": "text", "text": "Describe this image." }
]
}
]
}
Streaming
With stream: true, the response is an Anthropic event stream. Consumers
should handle message_start, content-block events, message_delta, and
message_stop; text arrives incrementally in content_block_delta events.
The exact event sequence follows the Anthropic Messages API.
curl -N -X POST "https://api.llmapi.ai/v1/messages" \
-H "Authorization: Bearer $LLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"max_tokens": 256,
"stream": true,
"messages": [{"role":"user","content":"Explain SSE briefly."}]
}'
For Claude Code, set ANTHROPIC_BASE_URL to https://api.llmapi.ai without
/v1; Claude Code appends /v1/messages itself. See the
Claude Code setup guide and Anthropic API compatibility.
Token counting
POST /v1/messages/count_tokens accepts the same request body and returns an
estimated or provider-counted input token total. Native Claude requests use
Anthropic’s authoritative counter when available.
curl -X POST "https://api.llmapi.ai/v1/messages/count_tokens" \
-H "Authorization: Bearer $LLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"messages": [{"role":"user","content":"Count this message."}]
}'
The response is shaped like { "input_tokens": 7 }. For native Claude
models, LLM API uses Anthropic’s counter when available; for compatible models,
the result is a local estimate and should be treated as approximate.
Important compatibility notes
- This is not a universal adapter for every model in the catalog. OpenAI, Google, and other non-compatible models should use Chat Completions or Responses.
- A
provider/model name can pin a Claude model to a provider, for example aws-bedrock/claude-sonnet-4-6, if that provider exposes the Anthropic binding.
- For Claude Code, set
ANTHROPIC_BASE_URL=https://api.llmapi.ai without /v1; Claude Code appends /v1/messages itself. See Anthropic API compatibility.
- Use an LLM API key in the
Authorization: Bearer header. Anthropic account keys are not interchangeable with gateway keys.
API operation: POST /v1/messages
API operation: POST /v1/messages/count_tokens