OpenAIStreamChunk
Defined in: frontend/dist/types/adapters/openai.d.ts:215
OpenAI streaming response chunk structure.
Represents a single chunk in a Server-Sent Events (SSE) stream. Each chunk contains incremental content (delta) that should be appended to build the complete message. The stream ends when finish_reason is non-null.
- OpenAIRequest
- OpenAIResponse
- https://platform.openai.com/docs/api-reference/chat/streaming
Example
Section titled “Example”// Content chunk during streamingconst chunk: OpenAIStreamChunk = { id: 'chatcmpl-123', object: 'chat.completion.chunk', created: 1677652288, model: 'gpt-4', choices: [{ index: 0, delta: { content: 'Hello' }, finish_reason: null }]};
// Final chunk signaling completionconst finalChunk: OpenAIStreamChunk = { ...chunk, choices: [{ index: 0, delta: {}, finish_reason: 'stop' }]};Properties
Section titled “Properties”choices
Section titled “choices”choices:
object[]
Defined in: frontend/dist/types/adapters/openai.d.ts:225
Array of delta choices (usually just one)
delta:
object
Incremental content delta - append to previous content
delta.content?
Section titled “delta.content?”
optionalcontent:string
Incremental text content to append
delta.role?
Section titled “delta.role?”
optionalrole:"assistant"
Role (only in first chunk, usually ‘assistant’)
finish_reason
Section titled “finish_reason”finish_reason:
"length"|"stop"|"tool_calls"|"content_filter"|null
Non-null when stream is complete. Indicates why generation stopped
index:
number
Choice index in the array
created
Section titled “created”created:
number
Defined in: frontend/dist/types/adapters/openai.d.ts:221
Unix timestamp when the chunk was created
id:
string
Defined in: frontend/dist/types/adapters/openai.d.ts:217
Unique identifier for this stream
model:
string
Defined in: frontend/dist/types/adapters/openai.d.ts:223
Model generating the stream
object
Section titled “object”object:
"chat.completion.chunk"
Defined in: frontend/dist/types/adapters/openai.d.ts:219
Object type - always ‘chat.completion.chunk’ for streaming