Referência da API
Messages
Anthropic-compatible chat completions — for clients built against Claude's Messages API.
/v1/messagesSame model, same stack, same everything as
/v1/chat/completions — this endpoint
exists so Anthropic SDKs and Claude-native tools (Claude Code, for example)
work against Stac without translation on your side.
Authentication
Anthropic clients send the key differently than OpenAI clients do. Both are accepted:
x-api-keyheaderOpcionalThe Anthropic convention. Send the raw key, no Bearer prefix.
AuthorizationheaderOpcionalAlso accepted, as Bearer $STAC_API_KEY — same as chat completions.
anthropic-versionheaderOpcionalAccepted for compatibility. Not validated against a specific date.
Request body
modelstringObrigatórioIgnored — your stack's model is always used. Required only because the format expects the field.
messagesMessage[]ObrigatórioSame shape as Anthropic's Messages API: role (user or assistant) and
content (string, or an array of blocks).
max_tokensintegerObrigatórioPadrão: 8000Required by the Anthropic format. Clamped to the same floor of 8000 and ceiling of 16000 as chat completions.
systemstring | Block[]OpcionalReplaces your stack's configured system prompt (and knowledge-base context) for this request. Omit it to keep your stack's configured behavior.
streambooleanOpcionalPadrão: falseServer-sent events in Anthropic's streaming format
(message_start → content_block_delta* → message_stop), not OpenAI's.
ping events are interleaved while the model works through a long prompt —
ignore them, as the official SDKs do. If the machine fails before producing
any output, the stream ends with an error event instead of
message_stop; treat that as a failed request, not an empty answer.
toolsTool[]OpcionalAnthropic tool-use schema. Converted internally to the same tool-calling path as chat completions.
Image blocks ({ "type": "image", "source": { "type": "base64", ... } })
work the same way they do via image_url in chat completions — see
OCR via chat.
Example
curl "$ANTHROPIC_BASE_URL/v1/messages" \
-H "x-api-key: $ANTHROPIC_AUTH_TOKEN" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "your-stack-model",
"max_tokens": 1024,
"messages": [{ "role": "user", "content": "Hello" }]
}'Response
{
"id": "msg_9f2a1c",
"type": "message",
"role": "assistant",
"model": "your-stack-model",
"content": [{ "type": "text", "text": "Red, blue, and yellow." }],
"stop_reason": "end_turn",
"usage": {
"input_tokens": 14,
"output_tokens": 7,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 0
}
}The two cache_* counters are always 0 — Stac doesn't do prompt caching —
but they're always present, so a client that sums the three input counters to
track context usage gets a number rather than NaN.
Using a Claude-native tool
Point the tool's Anthropic environment variables at Stac instead of writing any request code:
ANTHROPIC_BASE_URL=https://api.trystac.com
ANTHROPIC_AUTH_TOKEN=$STAC_API_KEYSee Anthropic compatibility for the full Claude Code setup, including the context-window variable that keeps it from overrunning your plan's window.
count_tokens
POST /v1/messages/count_tokens is also available, for clients that call it
before sending the real request. It reports the same token count your actual
call would use.

