51cowork APIDocs
Open docs navigation

API Reference

Streaming and SSE

Streaming delivers events incrementally and can reduce time to first visible output without changing credit metering.

Quick answer

Set stream: true, consume SSE events incrementally, and close the upstream request when the caller cancels.

Mode
SSE / stream
cURL
-N
Timeout
First token + body
Retry
Bounded and deduplicated
01

Send a streaming request

Streamingbash
curl -N "https://api.51cowork.com/v1/chat/completions" \
  -H "Authorization: Bearer <key-from-dashboard>" \
  -H "Content-Type: application/json" \
  -d '{"model":"<model-from-v1-models>","stream":true,"messages":[{"role":"user","content":"Hello"}]}'
02

Consume events

  • Read each event or chunk rather than buffering the response.
  • Create an application request ID and correlate the gateway request_id.
  • When an error arrives after partial output, keep received events for diagnosis.
03

Cancel and retry

SituationAction
User cancellationPropagate AbortSignal or close response body
First-token timeoutIncrease read timeout and check reachability
Mid-stream disconnectDo not restart by default; avoid duplicate cost
429 / temporary 5xxHonor Retry-After and back off with a bound