Goal: after a successful non-streaming call, enable SSE streaming in about five minutes.
Prerequisites
You completed First request and have API_KEY and MODEL_ID.
curl example
curl -sSN "https://51kik.com/v1/chat/completions" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-d '{
"model": "'"$MODEL_ID"'",
"stream": true,
"messages": [{ "role": "user", "content": "Explain streaming in three sentences" }]
}'
| Item | Value |
|---|---|
stream | true |
Accept | text/event-stream |
curl -N | Disable buffering for live output |
Reading SSE
Each line looks like:
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"delta":{"content":"..."}}]}
Termination:
data: [DONE]
A chunk with usage may appear near the end (gateway forces include_usage on streams). Details: Streaming.
Client pitfalls
| Issue | Mitigation |
|---|---|
| Proxy buffers entire response | proxy_buffering off on nginx |
| Idle timeout mid-generation | Increase proxy read timeout |
Chunk JSON contains error | Treat as failure |
Official SDK
const stream = await client.chat.send({
chatRequest: {
model: "YOUR_MODEL_ID",
stream: true,
messages: [{ role: "user", content: "Hello" }],
},
});
for await (const chunk of stream) {
// OpenAI-shaped chat.completion.chunk
}
See Chat and streaming.
Anthropic surface
Streaming Messages: POST https://51kik.com/anthropic/v1/messages with stream: true. See Create message.