openclaw - 💡(How to fix) Fix Feature Request: Support token usage tracking for Bailian Coding Plan [2 comments, 2 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#52258Fetched 2026-04-08 01:13:38
View on GitHub
Comments
2
Participants
2
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
commented ×2

Root Cause

Coding Plan uses a fixed monthly fee + request count limit model instead of token-based billing. The API response does not include usage information unless stream_options: { include_usage: true } is set in the request (for streaming mode).

RAW_BUFFERClick to expand / collapse

Problem

When using Alibaba Cloud Bailian Coding Plan, the API does not return token usage in the response. As a result:

  • /status always shows Context: 0/203k (0%)
  • OpenClaw cannot track actual context usage
  • Users cannot see how much context window is being consumed

Root Cause

Coding Plan uses a fixed monthly fee + request count limit model instead of token-based billing. The API response does not include usage information unless stream_options: { include_usage: true } is set in the request (for streaming mode).

Proposed Solution

  1. Add support for stream_options.include_usage: true parameter when calling OpenAI-compatible APIs
  2. Allow users to configure this via model params in openclaw.json
  3. If the API returns usage data, use it to update context tracking

Reference

Environment

  • OpenClaw version: 2026.3.13 (61d171a)
  • Provider: bailian (Coding Plan)
  • Model: glm-5

extent analysis

Fix Plan

To fix the issue, we need to add support for stream_options.include_usage: true in the API request and update the context tracking accordingly. Here are the steps:

  • Update the API request to include stream_options:
import requests

# ...

stream_options = {"include_usage": True}
response = requests.post(
    "https://coding.dashscope.aliyuncs.com/v1",
    json={"model": "glm-5", "prompt": "...", "stream_options": stream_options}
)
  • Add a configuration option in openclaw.json to allow users to enable/disable this feature:
{
    "models": {
        "glm-5": {
            "stream_options": {
                "include_usage": true
            }
        }
    }
}
  • Update the context tracking logic to use the usage data returned in the API response:
if "usage" in response.json():
    usage_data = response.json()["usage"]
    # Update context tracking with usage data
    context_usage = usage_data["context_usage"]
    # ...

Verification

To verify that the fix worked, check the API response for the usage field and ensure that the context tracking is updated correctly. You can also test the configuration option in openclaw.json to enable/disable the feature.

Extra Tips

  • Make sure to handle cases where the usage field is not returned in the API response.
  • Consider adding logging or monitoring to track the usage data and context tracking updates.

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

openclaw - 💡(How to fix) Fix Feature Request: Support token usage tracking for Bailian Coding Plan [2 comments, 2 participants]