Streaming
Server-sent events, ending with data: [DONE].
Set stream to true to receive the answer as server-sent events in OpenAI chunk format. The stream ends with data: [DONE].
curl -N https://api.tessen.ai/v1/chat/completions \
-H "Authorization: Bearer $TESSEN_ZERO_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "project-zero",
"stream": true,
"messages": [{ "role": "user", "content": "Explain this regular expression: ^\\d{3}-\\d{4}$" }]
}'stream = client.chat.completions.create(
model="project-zero",
stream=True,
messages=[{"role": "user", "content": "Explain this regular expression: ^\\d{3}-\\d{4}$"}],
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")const stream = await client.chat.completions.create({
model: "project-zero",
stream: true,
messages: [{ role: "user", content: "Explain this regular expression: ^\\d{3}-\\d{4}$" }],
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}Refusals during a stream
A streaming response commits to HTTP 200 before the request is routed, so a refusal arrives as an error event in the stream instead of an HTTP status. Its type is the same code a non-streaming request would return.
data: {"error": {"message": "The Zero Pool is at capacity. It resets daily.", "type": "zero_capacity_unavailable", "capacity_state": "…", "reset_at": "…"}}Idempotency-Key is not honoured for streaming requests; retrying a stream may run it again.