API
Streaming
Consume partial output without losing failure semantics
Chat Completions and Responses can stream through server-sent events. Treat a stream as a long-lived request that may end normally, be cancelled or become incomplete after headers are sent.
Chat Completions streams
Set stream=true and consume chat.completion.chunk data frames until data: [DONE]. Preserve finish_reason and tool-call deltas rather than concatenating text alone.
const stream = await client.chat.completions.create({
model: "policy/frontier",
messages: [{ role: "user", content: "Summarise this incident." }],
stream: true,
});
for await (const chunk of stream) process.stdout.write(chunk.choices[0]?.delta?.content ?? "");Responses event streams
Responses uses named events and may end with completed, incomplete or error state. Do not translate every terminal event into a successful completion.
Set deadlines and cancellation
Use an application deadline shorter than the end-user timeout, cancel abandoned streams and record the request ID. Never replay a side-effecting tool flow automatically after partial output.
