SSE Response Format
This document describes the Server-Sent Events (SSE) response format from the Bitseek Chat HTTP API.
Response Structure
Each SSE event contains a data: field with a JSON object following the OpenAI Chat Completions API format.
Event Format
data: {"id":"stream:chat:xxx","object":"chat.completion","created":1773042793,"model":"","choices":[{"index":0,"delta":{"content":"..."},"finish_reason":null}]}
Response Fields
| Field | Type | Description |
|---|---|---|
id |
string | Stream identifier (format: stream:chat:<uuid>) |
object |
string | Always "chat.completion" |
created |
number | Unix timestamp of the response creation |
model |
string | Model identifier (may be empty string) |
choices |
array | Array of completion choices |
Choices Array
Each choice object contains:
| Field | Type | Description | |
|---|---|---|---|
index |
number | Index of the choice (usually 0 for single response) | |
delta |
object | The content delta/increment | |
delta.content |
string | The incremental text content | |
finish_reason |
string\ | null | Reason for completion (null while streaming, "stop" when done) |
Stream Completion
When finish_reason is "stop", the stream has completed.
Example Response Flow
First chunk:
data: {"id":"stream:chat:26e9476e-14e9-4165-915a-723ccbbaa5ad","object":"chat.completion","created":1773042793,"model":"","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}
Middle chunk:
data: {"id":"stream:chat:26e9476e-14e9-4165-915a-723ccbbaa5ad","object":"chat.completion","created":1773042793,"model":"","choices":[{"index":0,"delta":{"content":"! How"},"finish_reason":null}]}
Final chunk (with finish_reason: "stop"):
data: {"id":"stream:chat:c51514fb-eaec-4f38-9bd9-6497993161c7","object":"chat.completion","created":1773044133,"model":"","choices":[{"index":0,"delta":{"content":""},"finish_reason":"stop"}]}
Parsing SSE Data
When parsing SSE responses:
- Split by lines starting with
data: - Extract the JSON after
data: - Check for
finish_reason === "stop"to detect completion - Concatenate all
delta.contentvalues to get the complete response
Example Parser (JavaScript)
const eventSource = new EventSource('https://chat-proxy.bitseek.ai/v1/chat/completions');
let fullContent = '';
eventSource.onmessage = (event) => {
const data = JSON.parse(event.data);
const choice = data.choices[0];
// Check if stream is complete
if (choice.finish_reason === 'stop') {
console.log('Response complete:', fullContent);
eventSource.close();
return;
}
const content = choice.delta?.content || '';
fullContent += content;
process.stdout.write(content); // Stream to console
};