Expand description
Reassemble OpenAI-compatible SSE streaming responses into non-streaming format.
When an OpenAI-compatible API streams a response as Server-Sent Events (SSE), each event contains a partial “chunk” of the final response. This crate provides a function to merge those chunks into the equivalent non-streaming JSON response.
§Supported formats
- Chat completions (
/v1/chat/completions): mergeschoices[].deltafields intochoices[].message, concatenating string values (e.g.content,refusal) and assemblingtool_callsby index. Other non-string delta fields use last-value-wins. - Legacy completions (
/v1/completions): concatenateschoices[].text. - Responses API (
/v1/responses): extracts the full response from theresponse.completedevent. - Multiple choices: tracked independently by
index. - Usage: taken from the final chunk.
Format detection is automatic: if any event’s event field (from
eventsource_stream::Event) starts with "response.", the Responses API
path is used; otherwise the completions path.
Functions§
- reassemble
- Reassemble OpenAI-compatible streaming chunks into a non-streaming response.