XuanShu API

Streaming and WebSocket

SSE streaming, Responses WebSocket, and disconnect handling.

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>.

Streaming and WebSocket

Messages, Responses, Chat Completions, and selected Gemini actions support streaming; clients should handle incremental events, timeouts, and interruption.

Models and advanced capabilities depend on the current console configuration.

Request and call

Validate streaming with SSE first; Responses WebSocket requires a correct upgrade and connection lifecycle handling.

curl -N https://www.xuanshuapi.com/v1/chat/completions \
  -H "Authorization: Bearer <YOUR_API_KEY>" -H "content-type: application/json" \
  -d '{"model":"<MODEL_FROM_MODELS>","messages":[{"role":"user","content":"Count to three"}],"stream":true}'

Response and streaming behavior

SSE returns deltas in data lines and ends with the protocol terminal event; clients must tolerate empty deltas and interruption.

HTTP 200
data: {"choices":[{"delta":{"content":"1"}}]}
data: {"choices":[{"delta":{"content":" 2"}}]}
data: [DONE]

Key parameters

ParameterDescription
modelMust support the selected streaming protocol.
streamSet to true.
timeoutClient connect and read timeouts.

Typical failures

Fix 401/403 authentication before the handshake; inspect WebSocket upgrade for 426; prevent duplicate output and cost when retrying interruptions.

HTTP 401/403  # authentication before streaming
HTTP 426  # invalid WebSocket upgrade
HTTP 429/5xx  # bounded reconnect candidate

Next steps

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