#2668·rig

bug: Responses API streaming fails when events omit sequence_number

Author: jplockCreated Oct 1, 2026Updated Oct 1, 2026
  • I have looked for existing issues (including closed) about this

Bug Report

Streaming over the Responses API fails when a model is served through an OpenAI-compatible gateway (LiteLLM in our case). The stream is rejected during deserialization:

JsonError: data did not match any variant of untagged enum StreamingCompletionChunk

The failing field is sequence_number. In crates/rig-core/src/providers/openai/responses_api/streaming.rs it is a required u64 on the streaming structs:

ResponseChunk            line 198
StreamingItemDoneOutput  line 1330
ContentPartChunk         line 1337
DeltaTextChunk           line 1416
DeltaTextChunkWithItemId line 1424
OutputTextChunk          line 1431
RefusalTextChunk         line 1438
ArgsTextChunk            line 1446
SummaryPartChunk         line 1453
SummaryTextChunk         line 1460

OpenAI sends sequence_number on every streaming event, so OpenAI models work. LiteLLM does not send it on most events when it translates a non-OpenAI model (for example an Anthropic or Bedrock backed model) into the Responses format. Because the field is required, serde cannot match any variant and the whole stream is dropped. One missing integer discards a valid response. Non-streaming calls to the same model work, because that path does not require the field.

Reproduction

Point an OpenAI Responses client at an OpenAI-compatible gateway that serves a translated (non-OpenAI) model, then stream a completion.

Two events from the same gateway show the difference. The first is a GPT model and includes the field. The second is a translated Claude model and does not.

data: {"type":"response.output_text.delta","item_id":"msg_a","output_index":0,"content_index":0,"delta":"ok","sequence_number":4,"model":"gpt-5"}
data: {"type":"response.output_text.delta","item_id":"msg_b","output_index":0,"content_index":0,"delta":"OK","model":"claude"}

The second event has no sequence_number, and deserialization fails with the error above.

Expected behavior

The stream decodes. sequence_number is an ordering hint, and events already arrive in order over SSE, so a missing value should not discard a valid response.

Proposed change: make sequence_number optional on the Responses streaming structs.

rust
#[serde(default)]
pub sequence_number: Option<u64>,

A present value still parses into Some, so OpenAI responses are unaffected.

Screenshots

Not applicable.

Additional context

The OpenAI provider in rig is used against OpenAI-compatible servers, not only OpenAI. LiteLLM is a common way to put many models behind one OpenAI-shaped endpoint. When a model is served by translation, streaming is unusable even though the content is correct and the events are otherwise well formed.

The Vercel AI SDK does not require this field, which is why clients built on it read the same stream that rig rejects. Its stream schema openaiResponsesChunkSchema, in packages/openai/src/responses/openai-responses-api.ts, only reads sequence_number on error events (response.failed, and the two error chunk schemas). The normal events it decodes, such as response.output_text.delta, response.created, and response.output_item.added, do not list sequence_number at all, so a missing value is ignored rather than fatal.

Version: rig-core 0.42.0.