openclaw - 💡(How to fix) Fix [Bug] openai-completions streaming: Context always shows 0 — missing stream_options include_usage [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#59328Fetched 2026-04-08 02:25:58
View on GitHub
Comments
2
Participants
2
Timeline
5
Reactions
0
Timeline (top)
commented ×2cross-referenced ×1mentioned ×1subscribed ×1

When using openai-completions API type with providers that strictly follow the OpenAI spec (e.g., Alibaba Cloud Bailian/DashScope), /status always shows Context: 0 because the provider returns usage: null in streaming chunks.

Root Cause

The OpenAI Chat Completions API spec requires clients to explicitly send stream_options: {"include_usage": true} in streaming requests to receive token usage data. Without this parameter, compliant providers return usage: null in every chunk.

Verified by curl testing against Bailian (DashScope):

  • stream: true WITHOUT stream_options → every chunk has "usage": null, no usage data at all
  • stream: true WITH "stream_options": {"include_usage": true} → final chunk returns full usage: {"prompt_tokens": 9, "completion_tokens": 30, "total_tokens": 39}

Fix Action

Fix / Workaround

Attempted Workaround

RAW_BUFFERClick to expand / collapse

Summary

When using openai-completions API type with providers that strictly follow the OpenAI spec (e.g., Alibaba Cloud Bailian/DashScope), /status always shows Context: 0 because the provider returns usage: null in streaming chunks.

Root Cause

The OpenAI Chat Completions API spec requires clients to explicitly send stream_options: {"include_usage": true} in streaming requests to receive token usage data. Without this parameter, compliant providers return usage: null in every chunk.

Verified by curl testing against Bailian (DashScope):

  • stream: true WITHOUT stream_options → every chunk has "usage": null, no usage data at all
  • stream: true WITH "stream_options": {"include_usage": true} → final chunk returns full usage: {"prompt_tokens": 9, "completion_tokens": 30, "total_tokens": 39}

Impact

  1. /status always shows Context: 0/1.0m (0%) — no way to monitor context growth
  2. Auto-compaction cannot trigger based on real token count (only triggers on model overflow errors)
  3. Sessions can grow unbounded until the provider returns HTTP 500

Environment

  • OpenClaw: 2026.3.28 (f9b1079)
  • Provider: Alibaba Cloud Bailian (DashScope) via openai-completions API
  • Model: qwen3.5-plus (1M context window)
  • Config: agents.defaults.models["bailian/qwen3.5-plus"].params.stream_options was attempted but not forwarded to the API request body

Expected Behavior

OpenClaw should send stream_options: {"include_usage": true} in all streaming requests to openai-completions API providers, so that token usage is properly tracked.

Attempted Workaround

Tried setting params.stream_options.include_usage: true in model config — this was not forwarded to the API request body (params likely only supports known fields like transport, cacheRetention, etc.).

Suggested Fix

Add stream_options: {"include_usage": true} to the streaming request body in the openai-completions provider implementation. This is standard OpenAI API behavior and should not break any providers.

Reference: OpenAI API docs - stream_options

extent analysis

TL;DR

Add stream_options: {"include_usage": true} to the streaming request body in the openai-completions provider implementation to properly track token usage.

Guidance

  • Verify that the stream_options parameter is correctly forwarded to the API request body by checking the request payload in the OpenClaw logs or using a tool like curl.
  • Update the openai-completions provider implementation to include stream_options: {"include_usage": true} in all streaming requests.
  • Test the updated implementation using a tool like curl to ensure that the usage field is properly populated in the response chunks.
  • Review the OpenClaw configuration to ensure that the stream_options parameter is correctly set for the bailian/qwen3.5-plus model.

Example

{
  "stream": true,
  "stream_options": {
    "include_usage": true
  }
}

This example shows the correct format for the stream_options parameter in the API request body.

Notes

The suggested fix assumes that the openai-completions provider implementation can be modified to include the stream_options parameter. If this is not possible, an alternative workaround may be necessary.

Recommendation

Apply the suggested fix by adding stream_options: {"include_usage": true} to the streaming request body in the openai-completions provider implementation, as this is the standard OpenAI API behavior and should not break any providers.

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