MisarMisar Docs

Anthropic Messages

Anthropic-compatible messages via POST /v1/messages, with claude-* passthrough.

Authentication

POST /v1/messages accepts either Authorization: Bearer <API_KEY> or the Anthropic-style x-api-key: <API_KEY> header. Gateway base URL: https://api.misar.dev.

This endpoint implements the Anthropic Messages wire format, so setting ANTHROPIC_BASE_URL=https://api.misar.dev routes Claude Code (or the Anthropic SDK) through MisarCoder. Requests are translated Anthropic → OpenAI → MoE router → Anthropic response.

POST/v1/messages

Create a message. Behavior depends on the requested model:

  • claude-* models — the request is forwarded directly to Anthropic (api.anthropic.com), preserving cache_control. The bearer/x-api-key token you send is used as the upstream Anthropic key. Both streaming and non-streaming are proxied verbatim.
  • All other models — the token is validated against the gateway key, the Anthropic request is translated to OpenAI messages, and the internal MoE router serves it.

Request body

modelstringbodyrequired

Model id. claude-* triggers direct Anthropic passthrough; any other id routes through the MoE engine.

messagesArray<{role, content}>bodyrequired

Anthropic messages. content may be a string or an array of content blocks (text, tool_result, ...).

systemstring | Array<{type:'text', text}>body

System prompt, as a string or a list of text blocks.

max_tokensintegerbody

Maximum tokens to generate. For MoE routing the value is floored at 1024 to leave room for reasoning tokens.

streambooleanbodydefault: false

When true, returns an Anthropic-format text/event-stream.

Response

For claude-* models the raw Anthropic response is returned unchanged. For MoE-routed models the gateway returns an Anthropic-shaped message object (type: "message", role: "assistant", content blocks, usage).

Request
curl https://api.misar.dev/v1/messages \
  -H "x-api-key: $MISARCODER_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3:8b",
    "max_tokens": 1024,
    "messages": [{ "role": "user", "content": "Say hello." }]
  }'
200 — Message
{
  "id": "msg_...",
  "type": "message",
  "role": "assistant",
  "content": [{ "type": "text", "text": "Hello!" }],
  "model": "qwen3:8b",
  "usage": { "input_tokens": 9, "output_tokens": 3 }
}

Token counting

Count tokens for an Anthropic-format request without generating a completion:

curl https://api.misar.dev/v1/messages/count_tokens \
  -H "Authorization: Bearer $MISARCODER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "model": "qwen3:8b", "messages": [{ "role": "user", "content": "Hello" }] }'

Status codes

  • 200 — Message returned (or stream opened).
  • 400 — Invalid JSON body.
  • 401 — Missing or invalid API key.
  • 502 — Upstream provider error.
  • 503 — Model router not initialized.
  • 504 — Upstream timeout.