XuanShu API

Messages API

Public Claude Messages and token-counting compatible endpoints.

Last verified:

Connection and authentication

Unified OpenAI-compatible Base URL: https://www.xuanshuapi.com/v1

OpenAI-compatible APIs use Authorization: Bearer <YOUR_API_KEY>; Claude Messages also accepts x-api-key: <YOUR_API_KEY>; Gemini v1beta uses x-goog-api-key: <YOUR_API_KEY>.

Messages API

POST /v1/messages supports regular and streaming responses; POST /v1/messages/count_tokens estimates tokens before execution.

Claude models and tool support depend on the current console configuration.

Request and call

Send system/user content in a Messages body; max_tokens is required and stream is optional.

curl https://www.xuanshuapi.com/v1/messages \
  -H "x-api-key: <YOUR_API_KEY>" -H "content-type: application/json" \
  -d '{"model":"<MODEL_FROM_MODELS>","max_tokens":256,"messages":[{"role":"user","content":"Reply with OK"}],"stream":false}'

Response and streaming behavior

Non-streaming responses return content blocks and usage; stream=true returns incremental SSE events.

HTTP 200
{"type":"message","role":"assistant","content":[{"type":"text","text":"OK"}],"usage":{"input_tokens":12,"output_tokens":1}}

Key parameters

ParameterDescription
modelClaude model ID returned by Models or the console.
messagesOrdered roles and content.
max_tokensMaximum output tokens.
streamEnables incremental SSE events.

Typical failures

For 400 inspect the body and max_tokens; for 401 inspect the key; consider bounded backoff only for 429/5xx.

HTTP 400  # invalid body or unsupported parameter
HTTP 401  # missing or invalid API key
HTTP 429  # quota or rate limit
HTTP 5xx  # recoverable service failure

Next steps

Available models, multipliers, quotas, and some advanced capabilities depend on the current key and console configuration.