Skip to content

Function: createResponsesStreamTranslator()

createResponsesStreamTranslator(model, responseId): ResponsesStreamTranslator

Translate an upstream chat-completions SSE stream into the Responses SSE event stream a Responses client consumes.

Upstream chunks are chat.completion.chunk objects whose choices[0].delta carries incremental content (assistant text) and/or tool_calls (function calls, streamed by index with partial arguments). We emit the Responses lifecycle around them:

response.created -> per text run: output_item.added → output_text.delta* → output_item.done -> per tool call: output_item.added → function_call_arguments.delta* → function_call_arguments.done → output_item.done response.completed (with the assembled final response object)

The translator is intentionally tolerant: malformed/keepalive lines yield nothing.

string

string

ResponsesStreamTranslator