Skip to content

Streaming responses ​

Set stream: true in a chat-completion request to receive incremental output. The HTTP connection remains open while the server sends events.

Event format ​

The response content type is text/event-stream. A typical text-delta event looks like this illustrative example:

text
data: {"choices":[{"index":0,"delta":{"content":"Hello"}}]}

data: [DONE]

Do not assume every chunk contains text. SDKs may expose empty deltas, finish reasons, usage data or model-specific fields. Process the fields your application understands and preserve the ability to handle future fields.

JavaScript client ​

Use the official OpenAI JavaScript client on your server to handle SSE framing rather than splitting raw network packets yourself.

sh
npm install openai
js
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: process.env.STREAMINGTELLIGENCE_API_KEY,
  baseURL: process.env.STREAMINGTELLIGENCE_BASE_URL,
});

const stream = await client.chat.completions.create({
  model: process.env.STREAMINGTELLIGENCE_MODEL,
  messages: [{ role: 'user', content: 'Describe this moment.' }],
  stream: true,
});

try {
  for await (const chunk of stream) {
    process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
  }
} finally {
  stream.controller.abort();
}

Disconnections and retries ​

Cancel the request when the user leaves or no longer needs the answer. Treat a connection that closes before completion as interrupted; do not silently concatenate a second independent generation onto the first.

Retry transient failures with bounded exponential backoff. Automatic retries can consume additional usage. Authentication and request-validation errors need a corrected request, not repeated retries.

Multimodal streaming ​

Supported input formats, context limits and session transports depend on the selected model. Follow its published interface contract when integrating continuous camera input or historical context; do not assume a chat-completion endpoint also accepts WebSocket connections.

StreamingTelligence Lab