You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The OpenAI-compatible gateway (opencode.ai/zen/go, /v1/chat/completions) emits non-standard SSE chunks when the client sends stream_options: {"include_usage": true}. This breaks OpenAI-compatible clients that rebuild the streamed response (e.g. LiteLLM crashes with litellm.APIError: Error building chunks for logging/streaming usage calculation).
Without stream_options, the same endpoint streams clean OpenAI-format chunks.
Empty choices: [] on the first chunks — OpenAI streams always start with a chunk containing choices[0].delta.role; clients use the first chunk to seed the response object.
id and model empty strings on mid-stream chunks — chunks should carry stable id/model.
Trailing data: {"choices":[],"cost":"0"} — not a valid OpenAI chunk (no id/object/created/model); the cost field is non-standard.
Content chunk's delta has no role (fine in the middle, but the first real chunk should carry it).
Impact
Any strict OpenAI-compatible client that accumulates chunks and rebuilds the full response (logging/usage calculation) crashes. LiteLLM (v1.84.0, and still in v1.97.0) raises Error building chunks for logging/streaming usage calculation because it assumes the first chunk with choices has a non-empty array with a delta.role.
Suggestion: only emit chunks with empty choices as the final usage chunk (like OpenAI does), keep id/model populated on every chunk, and drop the cost trailer (or put it inside the usage chunk).
This issue might be a duplicate of existing issues. Please check:
OpenAI-compatible cost chunk omits required stream fields #39061: Reports the same non-standard trailing {"choices":[],"cost":"0"} SSE chunk emitted by the Zen OpenAI-compatible endpoint, which lacks required fields (id, object, created, model). Your report extends this with additional symptoms (empty choices on early chunks, missing id/model on mid-stream chunks), but the core trailing cost chunk issue overlaps significantly.
Activity
github-actions commentedon Aug 16, 2026
This issue might be a duplicate of existing issues. Please check:
{"choices":[],"cost":"0"}SSE chunk emitted by the Zen OpenAI-compatible endpoint, which lacks required fields (id,object,created,model). Your report extends this with additional symptoms (emptychoiceson early chunks, missingid/modelon mid-stream chunks), but the core trailing cost chunk issue overlaps significantly.fix(models): keep opencode-go off the streaming usage request
github-actions commentedon Oct 16, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.