Don’t wait for the last token.
Set stream: true to receive server-sent events. Each event’s data: payload contains a completion chunk. The stream ends with data: [DONE].
data: {"choices":[{"delta":{"content":"Hello"}}]}
data: {"choices":[{"delta":{"content":" there."}}]}
data: [DONE]This is an illustrative protocol fragment, not a real API response or a usage record.
Handle interruption explicitly
Do not automatically replay a partially consumed stream. A disconnected connection does not always mean that the model stopped generating. Check the request log and trace identifier before retrying billable work.
curl https://unlimit.chat/v1/chat/completions \
-H "Authorization: Bearer $UNLIMIT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "YOUR_MODEL_ID",
"messages": [
{"role": "user", "content": "What if we built something different?"}
],
"stream": true
}'