Text and streaming

Text and streaming

Download Markdown ↓

Use one chat endpoint for normal responses and SSE streaming.

Basic endpoint#

Send POST /v1/chat/completions with at least model and messages. For multi-turn chat, the client generally needs to send the history it wants to preserve.

bash
curl 'https://api.xsopc.com/v1/chat/completions' \
  -H "Authorization: Bearer $XINGSUAN_API_KEY" \
  -H 'Content-Type: application/json' \
  --data-binary @- <<JSON
{
  "model": "$XINGSUAN_MODEL",
  "messages": [
    {
      "role": "user",
      "content": "Hello"
    }
  ]
}
JSON

Parameters vary by model#

Field Guidance
model Complete model ID published by the platform
messages Message array; media requires corresponding model support
stream Set true to request streaming
temperature Optional; support and range vary
max_tokens and similar output limits Use a field supported by the model; avoid conflicting limits

Reasoning content, tools, structured output and extra options are not supported by every model. Follow its details rather than copying another model's request unchanged.

Request an SSE stream#

bash
curl -N 'https://api.xsopc.com/v1/chat/completions' \
  -H "Authorization: Bearer $XINGSUAN_API_KEY" \
  -H 'Content-Type: application/json' \
  --data-binary @- <<JSON
{
  "model": "$XINGSUAN_MODEL",
  "messages": [
    {
      "role": "user",
      "content": "Hello"
    }
  ],
  "stream": true
}
JSON

curl -N disables client output buffering. A normal stream uses text/event-stream. Handle event boundaries, empty deltas, termination markers and errors. A network chunk is not necessarily one complete JSON event.

Request usage reporting only when the model and channel support the relevant option. Missing a final usage event does not mean the request was free.

First-token latency and timeouts#

Latency includes the client network, queuing, upstream processing and proxy buffering. Long contexts, complex reasoning and concurrency can increase it. Streaming can display content as soon as it arrives.

Disable SSE buffering in your own gateway or reverse proxy and use a suitable read timeout. The documentation site is independent of generation requests; reading docs does not call a model.

Interruptions and retries#

A client disconnect does not guarantee the upstream has stopped. Generated output or completed work may still be billed. After a network timeout, inspect usage records before retrying to avoid duplicate requests.

Updated

Search docs