Skip to content

Token usage always shows 0 when using Zhipu Coding Plan API with @ai-sdk/openai-compatible #25986

Closed as not planned

Description

@mangxy

Description

When using @ai-sdk/openai-compatible with Zhipu's Coding Plan endpoint, the status bar always displays Context: 0% used and token cost is never tracked — despite the upstream API returning valid usage data in both streaming and non-streaming responses.

Note: This is a different issue from #20885 which covers @ai-sdk/openai (Responses API). This issue is specific to @ai-sdk/openai-compatible (Chat Completions API) with Zhipu's Coding Plan endpoint.

Configuration

"zhipu-coding-plan": {
  "npm": "@ai-sdk/openai-compatible",
  "options": {
    "apiKey": "{env:ZHIPU_API_KEY}",
    "baseURL": "https://open.bigmodel.cn/api/coding/paas/v4"
  }
}

Steps to Reproduce

  1. Configure @ai-sdk/openai-compatible with Zhipu Coding Plan endpoint (/api/coding/paas/v4)
  2. Start a conversation with any model
  3. Observe the status bar — Context: 0% used stays at zero

Verification

I verified the upstream API returns valid usage data via direct curl:

Non-streaming response

{
  "usage": {
    "completion_tokens": 15,
    "prompt_tokens": 6,
    "total_tokens": 21,
    "prompt_tokens_details": { "cached_tokens": 5 },
    "completion_tokens_details": { "reasoning_tokens": 1 }
  }
}

Streaming response (last chunk before [DONE])

{
  "usage": {
    "prompt_tokens": 6,
    "completion_tokens": 212,
    "total_tokens": 218,
    "prompt_tokens_details": { "cached_tokens": 5 },
    "completion_tokens_details": { "reasoning_tokens": 167 }
  }
}

Key Observations

  1. Same SDK, different baseURL, different result — I have another provider using the same @ai-sdk/openai-compatible SDK pointing to Zhipu's standard endpoint (https://open.bigmodel.cn/api/paas/v4), and context %used displays correctly there (~44-59%). The only difference is the baseURL path (/api/coding/paas/v4 vs /api/paas/v4).

  2. Session I/O shows correctly — The right panel displays 44K in / 166 out correctly, but the top bar Context: 0% used remains at zero.

  3. The Coding Plan endpoint may return a slightly different response structure — possibly missing or extra fields in the streaming SSE format that causes the SDK to fail to extract usage data.

Environment

  • OpenCode: v1.14.37 (latest as of 2026-05-05)
  • SDK: @ai-sdk/openai-compatible
  • Provider: Zhipu (智谱) Coding Plan API
  • Endpoint: https://open.bigmodel.cn/api/coding/paas/v4

Related

Activity

  1. github-actions commented on May 6, 2026

    @github-actions
    Contributor

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

    If your issue is distinct (e.g., specifically caused by a different response structure from the Zhipu Coding Plan endpoint), please add details explaining how it differs from the above, and we can keep this open.

  2. github-actions commented on Jul 8, 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