POST /v1/messages
Anthropic-compatible message generation, non-streaming and named SSE; speed, inference_geo and anthropic-beta work as officially documented.
Request
curl https://api.unioapi.com/v1/messages \
-H "x-api-key: $UNIO_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello"}]
}'Key parameters
| Parameter | Type | Notes |
|---|---|---|
model | string, required | Model identifier, echoed in responses |
max_tokens | integer, required | Output cap required by the Anthropic protocol |
messages | array, required | Anthropic-shaped message list |
stream | boolean | Named SSE event stream ending with message_stop |
speed | string | standard (default) or fast; see Service Tiers |
inference_geo | string | "us" keeps inference in the US and bills every item at 1.1×; see US-only Inference |
Requests must carry the anthropic-version header; fields are validated and run in the official
Anthropic format. The anthropic-beta header takes effect as sent — follow the official
documentation. For cache_control and the 5-minute / 1-hour lifetimes see
Caching & TTL.
Response (excerpt)
{
"model": "claude-sonnet-5",
"role": "assistant",
"content": [{ "type": "text", "text": "..." }],
"stop_reason": "end_turn",
"usage": {
"input_tokens": 10,
"cache_read_input_tokens": 0,
"cache_creation_input_tokens": 0,
"output_tokens": 25
}
}For requests with speed or inference_geo, the response usage.speed and usage.inference_geo
show the tier and region the request actually ran on.
POST /v1/messages/count_tokens
Counts the input tokens of a set of messages in the official format, without generating content and without a charge.
Errors
Every error, including authentication failures, uses the Anthropic error structure:
{
"type": "error",
"error": { "type": "invalid_request_error", "message": "..." },
"request_id": "..."
}See Errors for the full list.