Referência da API

Messages

Anthropic-compatible chat completions — for clients built against Claude's Messages API.

POST/v1/messages

Same 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-keyheaderOpcional

The Anthropic convention. Send the raw key, no Bearer prefix.

AuthorizationheaderOpcional

Also accepted, as Bearer $STAC_API_KEY — same as chat completions.

anthropic-versionheaderOpcional

Accepted for compatibility. Not validated against a specific date.

Request body

modelstringObrigatório

Ignored — your stack's model is always used. Required only because the format expects the field.

messagesMessage[]Obrigatório

Same shape as Anthropic's Messages API: role (user or assistant) and content (string, or an array of blocks).

max_tokensintegerObrigatórioPadrão: 8000

Required by the Anthropic format. Clamped to the same floor of 8000 and ceiling of 16000 as chat completions.

systemstring | Block[]Opcional

Replaces your stack's configured system prompt (and knowledge-base context) for this request. Omit it to keep your stack's configured behavior.

streambooleanOpcionalPadrão: false

Server-sent events in Anthropic's streaming format (message_startcontent_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[]Opcional

Anthropic tool-use schema. Converted internally to the same tool-calling path as chat completions.

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

200 OKjson
{
  "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
  }
}

Using a Claude-native tool

Point the tool's Anthropic environment variables at Stac instead of writing any request code:

.envbash
ANTHROPIC_BASE_URL=https://api.trystac.com
ANTHROPIC_AUTH_TOKEN=$STAC_API_KEY

See 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.