Skip to content

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

Closed as not planned

Description

@hoanghjx

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)

Activity

  1. github-actions commented on Jul 27, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    If your issue is distinct (e.g. specific to billing.summary frames and not addressed by fixes for the above), please note that in a comment.

  2. hoanghjx commented on Jul 27, 2026

    @hoanghjx
    Author

    image

  3. github-actions commented on Sep 26, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions