Skip to content

Messages API

ZERG exposes an Anthropic Messages API compatible endpoint. This enables Anthropic SDK clients and tooling to target ZERG directly.

Overview

The /api/v1/messages endpoint mirrors the Anthropic wire format. ZERG translates the request to the configured provider and returns Anthropic-formatted responses. Supports streaming via SSE for token-by-token output.

Authentication

Requires x-api-key: <token> header (Anthropic-compatible) or Authorization: Bearer <token> header. Tokens are issued by Mango.

Endpoints

Create Message

POST /api/v1/messages

Request Body:

json
{
  "model": "claude-sonnet-4-20250514",
  "max_tokens": 1024,
  "messages": [
    { "role": "user", "content": "Explain quicksort" }
  ],
  "system": "You are a helpful assistant.",
  "temperature": 0.7,
  "stream": false
}

Response (non-streaming):

json
{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "content": [
    { "type": "text", "text": "Quicksort is a divide-and-conquer algorithm..." }
  ],
  "model": "claude-sonnet-4-20250514",
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 42,
    "output_tokens": 156
  }
}

Supported Parameters:

ParameterTypeDefaultDescription
modelstringrequiredModel identifier from the model catalog
messagesarrayrequiredArray of message objects
max_tokensinteger4096Maximum tokens in the response
systemstring""System prompt
temperaturefloat0.7Sampling temperature
streambooleanfalseEnable SSE streaming
stop_sequencesstring[][]Custom stop sequences
top_pfloat1.0Nucleus sampling
thinkingobjectnullExtended thinking config {type: "enabled", budget_tokens: 2048}

Streaming (stream: true):

Returns SSE events following the Anthropic streaming format:

event: message_start
data: {"type": "message_start", "message": {...}}

event: content_block_start
data: {"type": "content_block_start", "index": 0, "content_block": {"type": "text", "text": ""}}

event: content_block_delta
data: {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": "Quicksort"}}

event: message_stop
data: {"type": "message_stop"}

Tool Use:

ZERG supports tool definition and execution through the Anthropic tool schema. Tools defined in the request are executed by the Luna agent runtime.

json
{
  "tools": [{
    "name": "web_search",
    "description": "Search the web",
    "input_schema": {
      "type": "object",
      "properties": {
        "query": { "type": "string" }
      }
    }
  }]
}

Error Codes:

CodeDescription
400Invalid request body
401Missing or invalid authentication
404Model not found or unavailable
429Rate limit exceeded
500Provider or internal error
529Provider overloaded

Example:

bash
curl http://127.0.0.1:11434/api/v1/messages \
  -H "x-api-key: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 500,
    "messages": [{"role": "user", "content": "Write a poem"}]
  }'

Released under the MIT License.