API Reference
Streaming and SSE
Streaming delivers events incrementally and can reduce time to first visible output without changing credit metering.
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
Send a streaming request
Streaming
bashcurl -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"}]}'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.
Cancel and retry
| Situation | Action |
|---|---|
| User cancellation | Propagate AbortSignal or close response body |
| First-token timeout | Increase read timeout and check reachability |
| Mid-stream disconnect | Do not restart by default; avoid duplicate cost |
| 429 / temporary 5xx | Honor Retry-After and back off with a bound |
