API Reference
Streaming
Set stream: true on Chat Completions to receive the response incrementally over Server-Sent Events, instead of waiting for the full completion.
curl https://api.dravenai.lat/v1/chat/completions \
-H "Authorization: Bearer sk-drv-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "your-model-id",
"messages": [{ "role": "user", "content": "Count to 5." }],
"stream": true
}'
completion = client.chat.completions.create(
model="your-model-id",
messages=[{"role": "user", "content": "Count to 5."}],
stream=True,
)
const stream = await client.chat.completions.create({
model: "your-model-id",
messages: [{ role: "user", content: "Count to 5." }],
stream: true,
});
Event format
The response has Content-Type: text/event-stream. Each event is a line beginning with data: , followed by a chat.completion.chunk object, ending in a final data: [DONE] line:
text/event-stream
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1750000000,"model":"your-model-id","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1750000000,"model":"your-model-id","choices":[{"index":0,"delta":{"content":"1"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1750000000,"model":"your-model-id","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":12,"completion_tokens":9,"total_tokens":21}}
data: [DONE]
How to consume it
- The first chunk always carries
delta.role: "assistant"with empty content, so you can initialize the message. - Subsequent chunks carry
delta.contentfragments — append them in order to reconstruct the full text. - The final chunk before
[DONE]has an emptydelta, a non-nullfinish_reason, and includesusagefor the whole response (equivalent to passingstream_options: { include_usage: true }on OpenAI). - The stream always ends with a literal
data: [DONE]line.
for chunk in stream:
delta = chunk.choices[0].delta.content
if delta:
print(delta, end="")
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || "");
}
Token usage is still counted against your rate limits for streamed requests — it's tallied as the stream completes, using the real token counts returned by the model provider.