Messages (Anthropic-compatible)
POST /v1/messages·POST /v1/messages/count_tokensLets Claude Code and other Anthropic clients use Nexith as their upstream
The gateway translates both ways at the protocol boundary and internally still runs the same Chat execution pipeline (routing, billing, guardrails, and caching are all reused). Externally it behaves as the standard Anthropic Messages API.
Authentication#
Two header styles are supported:
x-api-key: nx-...
anthropic-version: 2023-06-01or
Authorization: Bearer nx-...POST /v1/messages#
Body#
| Field | Type | Required | Description |
|---|---|---|---|
model |
string | ✅ | nexith-core |
messages |
array | ✅ | {role: "user"|"assistant", content} |
system |
string | blocks | — | Top-level system, translated into the first system message |
max_tokens |
integer | — | If omitted, no limit is set (the upstream default applies) |
stream |
bool | — | Defaults to false |
temperature |
number | — | |
top_p |
number | — | |
tools |
array | — | {name, description, input_schema} |
tool_choice |
object | — | Anthropic shape, translated into OpenAI tool_choice |
content can be a string or an array of content blocks (text, image, tool_use,
tool_result).
Response#
{
"id": "msg_chatcmpl-ab64f280-…",
"type": "message",
"role": "assistant",
"model": "nexith-core",
"content": [{"type": "text", "text": "ok"}],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {"input_tokens": 320, "output_tokens": 2}
}Tool calls are returned as tool_use blocks inside content.
Streaming#
With stream=true, responses use Anthropic SSE events, in the same order as the official API:
event: message_start
event: content_block_start
event: content_block_delta
event: content_block_stop
event: message_delta
event: message_stopObserved sample:
event: content_block_delta
data: {"delta":{"text":"ok","type":"text_delta"},"index":0,"type":"content_block_delta"}POST /v1/messages/count_tokens#
Estimates input tokens for the same messages / system / tools and returns:
{"input_tokens": 320}Used for Claude Code's context budget display; the estimation basis matches billing (a character-count approximation) and is not guaranteed to equal the upstream tokenizer exactly.
Client configuration (Claude Code)#
export ANTHROPIC_BASE_URL=https://api.nexith.ai
export ANTHROPIC_AUTH_TOKEN=nx-...
export ANTHROPIC_MODEL=nexith-coreSee Claude Code integration for details.