Skip to main content

Crate openai_reassembler

Crate openai_reassembler 

Source
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): merges choices[].delta fields into choices[].message, concatenating string values (e.g. content, refusal) and assembling tool_calls by index. Other non-string delta fields use last-value-wins.
  • Legacy completions (/v1/completions): concatenates choices[].text.
  • Responses API (/v1/responses): extracts the full response from the response.completed event.
  • 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.