openclaw - 💡(How to fix) Fix Bug: modelstudio (DashScope) API returns correct usage but session stores all zeros [1 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#60639Fetched 2026-04-08 02:48:52
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
closed ×1commented ×1locked ×1

When using the modelstudio provider (Alibaba Cloud DashScope) with GLM-5 or other models, the API correctly returns usage statistics in the response, but OpenClaw's session storage records all usage values as 0.

Root Cause

When using the modelstudio provider (Alibaba Cloud DashScope) with GLM-5 or other models, the API correctly returns usage statistics in the response, but OpenClaw's session storage records all usage values as 0.

Fix Action

Fix / Workaround

Workaround Attempts

Code Example

{
  "usage": {
    "prompt_tokens": 8,
    "completion_tokens": 352,
    "completion_tokens_details": {
      "reasoning_tokens": 348
    },
    "total_tokens": 360
  },
  "choices": [{
    "message": {
      "content": "梦。",
      "reasoning_content": "..."
    }
  }]
}

---

{
  "type": "message",
  "message": {
    "usage": {
      "input": 0,
      "output": 0,
      "totalTokens": 0,
      "cost": {"total": 0}
    }
  }
}

---

Tokens: unknown/203k (?%)

---

const rawInput = asFiniteNumber(raw.input ?? raw.inputTokens ?? raw.input_tokens ?? raw.promptTokens ?? raw.prompt_tokens);
const output = asFiniteNumber(raw.output ?? raw.outputTokens ?? raw.output_tokens ?? raw.completionTokens ?? raw.completion_tokens);

---

{
  "models": {
    "providers": {
      "modelstudio": {
        "baseUrl": "https://coding.dashscope.aliyuncs.com/v1",
        "api": "openai-completions",
        "models": [{
          "id": "glm-5",
          "contextWindow": 202752,
          "cost": {
            "input": 0,
            "output": 0
          }
        }]
      }
    }
  }
}
RAW_BUFFERClick to expand / collapse

Bug: modelstudio (DashScope) API returns correct usage but session stores all zeros

Summary

When using the modelstudio provider (Alibaba Cloud DashScope) with GLM-5 or other models, the API correctly returns usage statistics in the response, but OpenClaw's session storage records all usage values as 0.

Evidence

1. API Response (correct usage)

{
  "usage": {
    "prompt_tokens": 8,
    "completion_tokens": 352,
    "completion_tokens_details": {
      "reasoning_tokens": 348
    },
    "total_tokens": 360
  },
  "choices": [{
    "message": {
      "content": "梦。",
      "reasoning_content": "..."
    }
  }]
}

2. Session Storage (all zeros)

From ~/.openclaw/agents/main/sessions/*.jsonl:

{
  "type": "message",
  "message": {
    "usage": {
      "input": 0,
      "output": 0,
      "totalTokens": 0,
      "cost": {"total": 0}
    }
  }
}

3. OpenClaw Status Output

Tokens: unknown/203k (?%)

Analysis

Code Review

The normalizeUsage function in auth-profiles-B5ypC5S-.js should correctly parse the response:

const rawInput = asFiniteNumber(raw.input ?? raw.inputTokens ?? raw.input_tokens ?? raw.promptTokens ?? raw.prompt_tokens);
const output = asFiniteNumber(raw.output ?? raw.outputTokens ?? raw.output_tokens ?? raw.completionTokens ?? raw.completion_tokens);

This supports prompt_tokens and completion_tokens field names, which match the API response.

Potential Causes

  1. GLM-5's reasoning_content field: GLM-5 returns an extra reasoning_content field along with content. This might interfere with usage extraction logic.

  2. Usage data not passed to session storage: The usage data might be lost or overwritten with default values somewhere in the agent-runner pipeline.

  3. Stream processing issue: If streaming is enabled, the final usage might not be captured correctly.

Configuration

{
  "models": {
    "providers": {
      "modelstudio": {
        "baseUrl": "https://coding.dashscope.aliyuncs.com/v1",
        "api": "openai-completions",
        "models": [{
          "id": "glm-5",
          "contextWindow": 202752,
          "cost": {
            "input": 0,
            "output": 0
          }
        }]
      }
    }
  }
}

Environment

  • OpenClaw version: 2026.3.28
  • Node: v24.14.1
  • OS: macOS 26.3 (arm64)
  • Provider: modelstudio (Alibaba Cloud DashScope)
  • Model: glm-5 (also affects qwen3.5-plus, kimi-k2.5)

Expected Behavior

Session storage should record actual usage values from the API response, enabling accurate token tracking and cost estimation.

Workaround Attempts

Setting cost values to non-zero didn't help - the usage is still recorded as 0.


This bug affects all modelstudio models and prevents users from tracking their API usage and costs.

extent analysis

TL;DR

The issue with session storage recording all zeros for usage values can be addressed by verifying the data flow from the API response to session storage, focusing on potential interference from the reasoning_content field or data loss in the agent-runner pipeline.

Guidance

  • Review the normalizeUsage function to ensure it correctly handles the reasoning_content field returned by GLM-5 models.
  • Verify that the usage data from the API response is being passed correctly to session storage, checking for any potential overwrites or losses in the agent-runner pipeline.
  • Investigate if streaming is enabled and if it might be causing issues with capturing the final usage correctly.
  • Check the configuration and environment settings to ensure they are compatible with the modelstudio provider and GLM-5 model.

Example

// Example of modified normalizeUsage function to handle reasoning_content field
const rawInput = asFiniteNumber(raw.input ?? raw.inputTokens ?? raw.input_tokens ?? raw.promptTokens ?? raw.prompt_tokens);
const output = asFiniteNumber(raw.output ?? raw.outputTokens ?? raw.output_tokens ?? raw.completionTokens ?? raw.completion_tokens);
// Add logic to handle reasoning_content field if necessary

Notes

The issue seems to be related to the specific modelstudio provider and GLM-5 model, so any fixes or workarounds may need to be tailored to these components. Additionally, the reasoning_content field may require special handling to ensure accurate usage tracking.

Recommendation

Apply a workaround by modifying the normalizeUsage function to handle the reasoning_content field and verify the data flow to session storage, as the root cause of the issue is likely related to these components.

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