anomalyco / anomalyco/opencode

[BUG]: Type validation failed for billing.summary SSE event from SiliconFlow-compatible providers

Open
#39,087 2 comments 0 reactions 1 assignee View on GitHub

@kitlangton is already working on this.

Since Jul 27, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

When using a provider that injects billing metadata into the SSE stream (e.g., SiliconFlow-compatible APIs), opencode crashes with a type validation error because the response schema only accepts choices array or error object, but billing summary events have neither.

Error

Type validation failed: Value: {"billing":{"source":"request","occurred_month":"2026-07","request":{"success":true,"stream":true,"tokens":{"input_tokens":29816,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":873,"reasoning_tokens":516,"total_tokens":30689},"cost_cny":{"input":"0.2087","cache_creation":"0.0000","cache_read":"0.0000","output":"0.0367","reasoning":"0.0000","request":"0.0000","duration":"0.0000","quantity":"0.0000","parameter":"0.0000","total":"0.2454"}},"api_key_period":{"period":{"usage_type":"","reset_cycle":"","period_key":""},"stats":{"request_count":0,"success_count":0,"error_count":0,"stream_request_count":0},"tokens":{"input_tokens":0,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":0,"reasoning_tokens":0,"total_tokens":0},"cost_cny":{"total":""}}},"object":"billing.summary"}.
Error message: [
  {
    "code": "invalid_union",
    "errors": [
      [
        {
          "expected": "array",
          "code": "invalid_type",
          "path": ["choices"],
          "message": "Invalid input: expected array, received undefined"
        }
      ],
      [
        {
          "expected": "object",
          "code": "invalid_type",
          "path": ["error"],
          "message": "Invalid input: expected object, received undefined"
        }
      ]
    ],
    "path": [],
    "message": "Invalid input"
  }
]

Root Cause

The SSE stream response validation uses a union type expecting either:

  1. A successful response with a choices array, OR
  2. An error response with an error object

Providers like SiliconFlow inject extra SSE events with "object": "billing.summary" at the end of the stream. These are not part of the OpenAI spec and cause a hard validation failure instead of being silently ignored.

Expected Behavior

Unknown SSE event object types (e.g., billing.summary) should be silently ignored rather than throwing a validation error.

Steps to Reproduce

  1. Configure opencode with a SiliconFlow-compatible provider
  2. Send any chat request
  3. Observe the Type validation failed error in the output

Environment

  • Provider: SiliconFlow-compatible API (injects billing.summary into SSE stream)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.