Skip to content

AIHubMix provider: streaming completes output but errors near end with ZodError (invalid_union: reason/part/delta) #7439

Closed

Description

@qiyuanhuakai

Description

When using the built-in AIHubMix provider, OpenCode can stream most of the assistant output, but near the end of the stream it throws a ZodError and marks the request as failed.

The error is an invalid_union with fields like:

path ["reason"]: expected string, received object
path ["part"]: expected object, received undefined
path ["delta"]: expected string, received undefined

I use the built-in provider XIAOMI now, and it just works well.

Plugins

at first with oh-my-opencode, and it can be reproduced with none

OpenCode version

1.1.8, and can be reproduced in 1.1.6 and 1.1.1

Steps to reproduce

Use the bulit-in AIHubMix provider:

  • Select an AIHubMix model.
  • Send any prompt (e.g. hello / 你好?).
  • Observe streaming output appears, then near completion OpenCode throws ZodError.
    Model tested:
  • Claude Haiku 4.5 (built-in)
  • GPT-5.2 (built-in)
  • glm-4.7 (built-in)
  • grok-4-1-fast-non-reasoning(added by myself)
  • gemini-3-flash-preview (added by myself)

Screenshot and/or share link

Image

Operating System

Ubuntu 24.04, in WSL2

Terminal

Windows Terminal

Activity

  1. github-actions commented on Jan 9, 2026

    @github-actions
    Contributor

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

    These issues all involve streaming response validation failures where the expected types don't match the actual API response formats. If your issue is specific to AIHubMix provider or involves different API response structures, feel free to ignore these references.

  2. qiyuanhuakai commented on Jan 9, 2026

    @qiyuanhuakai
    Author
    cat ~/.cache/opencode/package.json
    {
      "dependencies": {
        "opencode-copilot-auth": "0.0.9",
        "opencode-anthropic-auth": "0.0.5",
        "oh-my-opencode": "2.14.0",
        "@aihubmix/ai-sdk-provider": "1.0.1"
      }
    }%    
    
  3. xrh0905 commented on Jan 11, 2026

    @xrh0905

    Can confirm this issue on latest opencode desktop (1.0.152).
    Possible duplicated as #7674 .

  4. qiyuanhuakai commented on Jan 11, 2026

    @qiyuanhuakai
    Author

    将 provider 从 @aihubmix/ai-sdk-provider 切换到 @ai-sdk/openai-compatible 后,一切就正常工作了。
    既然 aihubmix 本身就是 OpenAI 兼容的,可能是专属的 provider 实现本身存在某些兼容性问题。建议排查一下。

    After switching the provider from @aihubmix/ai-sdk-provider to @ai-sdk/openai-compatible, everything works fine.
    Since aihubmix is already OpenAI-compatible, there might be some compatibility issues in the dedicated provider implementation. This might be worth investigating.

  5. zguiyang commented on Jan 17, 2026

    @zguiyang

    Hi team,

    I was wondering if there are any updates or a tentative timeline for a fix? I rely heavily on this service for my daily workflow, so I’m looking forward to getting it back up and running. > Thanks for all your hard work on this!

  6. elzorrorebelde commented on Jan 18, 2026

    @elzorrorebelde
    cat ~/.cache/opencode/package.json
    {
      "dependencies": {
        "opencode-copilot-auth": "0.0.9",
        "opencode-anthropic-auth": "0.0.5",
        "oh-my-opencode": "2.14.0",
        "@aihubmix/ai-sdk-provider": "1.0.1"
      }
    }%    
    

    In my case, I have this:

    {
      "dependencies": {
        "opencode-copilot-auth": "0.0.5",
        "opencode-anthropic-auth": "0.0.2",
        "@ai-sdk/openai-compatible": "latest",
        "@ai-sdk/openai": "latest",
        "@ai-sdk/anthropic": "latest"
      }
    }
    

    and I also see those errors.

  7. Rakan-AlZagha commented on Feb 22, 2026

    @Rakan-AlZagha

    Experiencing the same issue with a custom OpenAI-compatible provider.

    I'm building a provider using @ai-sdk/openai-compatible (v2.0.30). Streaming works fine—text renders correctly—but validation fails at the end with:

    [{"expected":"string","code":"invalid_type","path":["reason"],"message":"Invalid input: expected string, received object"}]
    

    Environment

    • OpenCode: 1.2.10
    • OS: macOS (Darwin 25.2.0)
    • Provider: Custom via @ai-sdk/openai-compatible
    • Backend: Qwen3-32B on vLLM

    What I've ruled out

    1. Server response is clean — returns {"type":"completion"} with no reason field
    2. SSE format is correct — "finish_reason":"stop" as a string, matching the OpenAI spec exactly
    3. AI SDK works standalone — using the same provider with streamText directly passes without issues
    4. Only fails inside OpenCode — the ["reason"] path in the validation error doesn't exist in @ai-sdk/openai-compatible's schema (which uses finish_reason), so this appears to be OpenCode's own validation layer expecting a different shape

    This is blocking adoption of custom providers. Happy to provide logs or a minimal repro—any workaround or timeline for a fix would be appreciated. @rekram1-node

  8. github-actions commented on Apr 24, 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

bugSomething isn't workingwindows

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions