Cookbook
Streaming with Node.js
Runnable SSE streaming example using only Node.js built-ins.
A complete example uses fetch, TextDecoderStream, and no external packages.
Key behaviors demonstrated:
- Sends the required
Idempotency-Keyandmax_completion_tokens. - Uses strict
stream_options: { include_usage: true }. - Captures
X-Request-Idfrom response headers. - Reuses
NINETWOS_IDEMPOTENCY_KEYwhen set, so a retry can recover the same logical request. - Detects a completed replay returned as JSON even though the original
request used
stream=true. - Reads the response body incrementally and splits SSE frames on blank lines.
- Handles
ChatCompletionChunk,UsageEvent, and[DONE]. - Treats
finish_reasonor[DONE]as terminal markers; a transport EOF is not terminal. - Renders only
delta.content;delta.reasoning_contentis an unstable backend passthrough and is not accumulated by the gateway.
See Chat and streaming for the full source and recovery guidance.