ZBStream

Anthropic-Compatible API

ZBStream also exposes an Anthropic-compatible Messages API (/v1/messages). Point the official Anthropic SDK at ZBStream by changing the base URL — cURL, Python, Node.js, and Go are all supported.

Endpoint & Authentication

The Anthropic-compatible base URL has no /v1 suffix — the official SDK appends /v1/messages automatically. Authenticate with the x-api-key header (Authorization: Bearer is also accepted) and include anthropic-version.

x-api-key: $ZBSTREAM_API_KEY
anthropic-version: 2023-06-01
Content-Type: application/json
ParameterValueDescription
Base URLhttps://api.zbstream.comThe SDK appends /v1/messages automatically
Authx-api-key: <key>Same ZBStream API key as the OpenAI interface
Versionanthropic-version: 2023-06-01Recommended for forward compatibility

Send a Messages Request

The Messages API requires max_tokens, and the system prompt is a top-level field rather than part of the messages array. The answer is returned in the content array; usage is reported in usage.input_tokens / usage.output_tokens.

curl https://api.zbstream.com/v1/messages \
  -H "x-api-key: $ZBSTREAM_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-pro",
    "max_tokens": 1024,
    "messages": [
      { "role": "user", "content": "你好,请介绍一下 ZBStream API。" }
    ]
  }'

Streaming Responses

Add "stream": true to receive an SSE stream. Event types include message_start, content_block_delta, and message_stop.

curl https://api.zbstream.com/v1/messages \
  -H "x-api-key: $ZBSTREAM_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-pro",
    "max_tokens": 1024,
    "stream": true,
    "messages": [{ "role": "user", "content": "请逐步回答" }]
  }'

Common Request Fields

FieldRequiredDescription
modelYesModel id, matching /v1/models
messagesYesMessage array with user / assistant roles
max_tokensYesMaximum output tokens
systemNoTop-level system prompt
temperatureNoSampling temperature, model-dependent range
streamNoEnable SSE streaming
toolsNoTool definitions following the Anthropic schema

Differences from the OpenAI API

  • max_tokens is required by the Messages API but optional in the OpenAI API.
  • The system prompt is a top-level field, not a role=system message.
  • The response body is an array of content blocks (text, tool use, …) rather than a single message.content string.
  • Usage is reported as usage.input_tokens / usage.output_tokens, corresponding to prompt_tokens / completion_tokens in the OpenAI API.
  • Both interfaces share the same API key and credit account, billed at each model's rates.