Messages
/v1/messages is the Anthropic Messages compatible entrypoint for Claude Code and Anthropic protocol clients. The requested model must be available to the current API key.
Interface
| Item | Value |
|---|---|
| Method | POST |
| Path | /v1/messages |
| Content-Type | application/json |
| Authentication | Authorization: Bearer YOUR_API_KEY |
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Requested model. |
messages | array | Yes | Anthropic Messages style message array. |
max_tokens | integer | Usually | Maximum output tokens. |
system | string or array | No | System prompt. |
stream | boolean | No | Whether to stream the response. |
thinking | object | No | Reasoning configuration, applied by model and platform capability. |
metadata.user_id | string | No | Can be used for sticky sessions and request tracking. |
Request Example
bash
curl https://api.llmapi.site/v1/messages \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"model": "claude-sonnet-4-5",
"max_tokens": 512,
"messages": [
{ "role": "user", "content": "Summarize this request." }
]
}'Response — 200 OK
json
{
"id": "msg_123",
"type": "message",
"role": "assistant",
"model": "claude-sonnet-4-5",
"content": [
{
"type": "text",
"text": "Summary text."
}
],
"stop_reason": "end_turn",
"usage": {
"input_tokens": 24,
"output_tokens": 12
}
}When stream is true, the response uses Anthropic-compatible event streaming.
Token Count
/v1/messages/count_tokens provides Anthropic token counting. It checks subscription and balance, but does not acquire concurrency or record usage.
| Item | Value |
|---|---|
| Method | POST |
| Path | /v1/messages/count_tokens |
| Content-Type | application/json |
| Restriction | Not supported for OpenAI platform groups |
Request example:
bash
curl https://api.llmapi.site/v1/messages/count_tokens \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"model": "claude-sonnet-4-5",
"messages": [
{ "role": "user", "content": "Hello" }
]
}'OpenAI group response example:
json
{
"type": "error",
"error": {
"type": "not_found_error",
"message": "Token counting is not supported for this platform"
}
}Successful token count response:
json
{
"input_tokens": 42
}Errors
| Status | Cause |
|---|---|
400 | Request body, model, or message payload is invalid. |
401 | API key is missing or invalid. |
403 | Balance, quota, group, or subscription check failed. |
404 | Endpoint is not available for the current platform, or the requested model is unavailable. |
429 | Rate limit or concurrency limit was reached. |
500 / 502 / 503 | Gateway or upstream provider failed. |