openclaw - 💡(How to fix) Fix Token count not displayed in TUI status bar for openai-completions API providers [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#59105Fetched 2026-04-08 02:28:30
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Participants

Code Example

{
  "usage": {
    "completion_tokens": 164,
    "prompt_tokens": 7,
    "total_tokens": 171
  }
}

---

{
  "bailian": {
    "baseUrl": "https://coding.dashscope.aliyuncs.com/v1",
    "api": "openai-completions",
    "models": [
      {
        "id": "glm-5",
        "contextWindow": 202752,
        "maxTokens": 16384
      }
    ]
  }
}
RAW_BUFFERClick to expand / collapse

Bug Description

Token count shows as ? in TUI status bar when using models configured with openai-completions API type, even though the API returns valid usage data.

Steps to Reproduce

  1. Configure a model with openai-completions API type (e.g., bailian/glm-5, moonshot, qwen via proxy)
  2. Start OpenClaw TUI
  3. Observe status bar shows tokens ?/203k instead of actual token count

Expected Behavior

Token count should be displayed correctly (e.g., tokens 51k/203k)

Actual Behavior

Token count shows as question mark: tokens ?/203k

Evidence

API returns valid usage data:

{
  "usage": {
    "completion_tokens": 164,
    "prompt_tokens": 7,
    "total_tokens": 171
  }
}

But TUI does not display it.

Environment

Model Configuration

{
  "bailian": {
    "baseUrl": "https://coding.dashscope.aliyuncs.com/v1",
    "api": "openai-completions",
    "models": [
      {
        "id": "glm-5",
        "contextWindow": 202752,
        "maxTokens": 16384
      }
    ]
  }
}

Additional Context

  • /status command shows Context: 0/203k but also shows Cache: 100% hit · 51k cached
  • The functionality works correctly, only the display is affected
  • This likely affects all providers using openai-completions API type

extent analysis

TL;DR

The issue can likely be resolved by updating the token count parsing logic to correctly handle the usage data returned by the openai-completions API.

Guidance

  • Verify that the usage data from the API is being correctly received and parsed in the OpenClaw TUI code.
  • Check if the total_tokens value from the API response is being used to update the token count display in the TUI status bar.
  • Investigate if there are any differences in the API response format between the openai-completions API type and other API types that might be causing the issue.
  • Review the model configuration and API endpoint to ensure they are correctly set up to return the expected usage data.

Example

No code snippet is provided as the issue does not include enough information about the specific code implementation.

Notes

The issue seems to be specific to the openai-completions API type, so any fixes or workarounds may need to be tailored to this specific API.

Recommendation

Apply a workaround to update the token count parsing logic to correctly handle the usage data returned by the openai-completions API, as the root cause of the issue appears to be related to this specific API type.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING