Skip to content

Rulvar API reference


Rulvar API reference / @rulvar/openai / mapChatCompletionsStream

Function: mapChatCompletionsStream()

ts
function mapChatCompletionsStream(
   stream, 
   ids, 
options?): AsyncGenerator<ChatEvent, void>;

Defined in: packages/openai/src/wire.ts:779

Delta-patched chunk assembly for the degraded path; yields each canonical event as its chunk is consumed (same live-streaming contract as mapResponsesStream).

The chat dialect has no explicit terminal frame at this layer: the only completion signal is a finish_reason on the last choice chunk. A stream that drains without one is a truncated wire read, so the mapper fails closed with one retryable transport error (after forwarding any usage the provider did report, which was still paid for) instead of synthesizing a stop finish, unless options.signal shows the caller requested the abort.

Parameters

ParameterType
streamAsyncIterable&lt;Record&lt;string, unknown&gt;&gt;
idsOpenAiIdMap
options?{ signal?: AbortSignal; }
options.signal?AbortSignal

Returns

AsyncGenerator&lt;ChatEvent, void&gt;