anomalyco / anomalyco/opencode
[BUG]: Type validation failed for billing.summary SSE event from SiliconFlow-compatible providers
@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:
- A successful response with a
choicesarray, OR - An error response with an
errorobject
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
- Configure opencode with a SiliconFlow-compatible provider
- Send any chat request
- Observe the
Type validation failederror in the output
Environment
- Provider: SiliconFlow-compatible API (injects
billing.summaryinto SSE stream)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.