Bug type
Behavior bug (incorrect output/state without crash)
Summary
OpenClaw drops token usage for OpenAI-compatible custom providers in the openai-completions streaming path, even when the upstream provider returns valid usage data. As a result:
- session logs persist
usage.totalTokens = 0
- the dashboard shows
unknown/...
openclaw status --usage shows no usable session/provider usage
This does not appear to be a dashboard bug. The usage is already missing in the persisted session messages.
Steps to reproduce
- Configure a custom provider using api: "openai-completions".
- Use that provider for an agent.
- Send a simple prompt, for example:
openclaw agent --agent main --message "Reply with exactly OK."
- Check usage status:
openclaw status --usage
- Inspect the latest session log for the assistant message.
Expected behavior
If the upstream OpenAI-compatible provider returns valid usage fields, OpenClaw should persist them in the assistant message / agent metadata, and the dashboard / CLI should show actual token usage.
Actual behavior
OpenClaw still persists zero usage for the assistant message, for example:
"usage": {
"input": 0,
"output": 0,
"cacheRead": 0,
"cacheWrite": 0,
"totalTokens": 0,
"cost": {
"input": 0,
"output": 0,
"cacheRead": 0,
"cacheWrite": 0,
"total": 0
}
}
And the CLI shows:
- session tokens as unknown/...
- Usage: no provider usage available.
OpenClaw version
2026.3.13
Operating system
Ubuntu 24.4
Install method
npm global
Model
gpt-oss-120b, qwen3-235b-a22b-instruct-2507, qwen3-coder-30b-a3b-instruct, Qwen3-embedding-8b
Provider / routing chain
custom-api-scaleway-ai
Config file / key location
No response
Additional provider/model setup details
No response
Logs, screenshots, and evidence
Impact and severity
No response
Additional information
Non-streaming request
POST /chat/completions
Response includes:
"usage": {
"prompt_tokens": 72,
"completion_tokens": 8,
"total_tokens": 80
}
Streaming request with usage enabled
Request body includes:
{
"stream": true,
"stream_options": {
"include_usage": true
}
}
{
"choices": [],
"usage": {
"prompt_tokens": 72,
"completion_tokens": 8,
"total_tokens": 80
}
}
So the provider is not the problem, and the dashboard is not the primary problem either. The usage is being lost inside OpenClaw before persistence/display.
Additional Notes
- Updating from 2026.3.7 to 2026.3.13 did not fix the issue.
- A local workaround that injects stream_options.include_usage = true for the affected provider did not change the final persisted result.
- This suggests the usage is likely being dropped deeper in the OpenAI-compatible streaming ingestion path, possibly around the final SSE chunk handling or propagation into lastAssistant / agentMeta.
Suspected Area
The issue appears to be in the openai-completions streaming path for OpenAI-compatible providers, especially handling of the final SSE chunk with:
{
"choices": [],
"usage": { ... }
}
Potentially relevant area:
- the imported streamSimple path from @mariozechner/pi-ai
- usage propagation into final assistant message / agentMeta.lastCallUsage
Impact
This makes usage reporting effectively unusable for affected custom OpenAI-compatible providers:
- dashboard usage is wrong / empty
- CLI usage is wrong / empty
- local session cost / usage aggregation is incomplete
Suggested Fix Direction
- Verify that the final chat.completion.chunk SSE event carrying usage is not discarded when choices is empty.
- Ensure prompt_tokens, completion_tokens, and total_tokens are propagated into the final assistant message or agentMeta.lastCallUsage for openai-completions custom providers.
Bug type
Behavior bug (incorrect output/state without crash)
Summary
OpenClaw drops token usage for OpenAI-compatible custom providers in the
openai-completionsstreaming path, even when the upstream provider returns valid usage data. As a result:usage.totalTokens = 0unknown/...openclaw status --usageshows no usable session/provider usageThis does not appear to be a dashboard bug. The usage is already missing in the persisted session messages.
Steps to reproduce
openclaw agent --agent main --message "Reply with exactly OK."
openclaw status --usage
Expected behavior
If the upstream OpenAI-compatible provider returns valid usage fields, OpenClaw should persist them in the assistant message / agent metadata, and the dashboard / CLI should show actual token usage.
Actual behavior
OpenClaw still persists zero usage for the assistant message, for example:
"usage": {
"input": 0,
"output": 0,
"cacheRead": 0,
"cacheWrite": 0,
"totalTokens": 0,
"cost": {
"input": 0,
"output": 0,
"cacheRead": 0,
"cacheWrite": 0,
"total": 0
}
}
And the CLI shows:
OpenClaw version
2026.3.13
Operating system
Ubuntu 24.4
Install method
npm global
Model
gpt-oss-120b, qwen3-235b-a22b-instruct-2507, qwen3-coder-30b-a3b-instruct, Qwen3-embedding-8b
Provider / routing chain
custom-api-scaleway-ai
Config file / key location
No response
Additional provider/model setup details
No response
Logs, screenshots, and evidence
Impact and severity
No response
Additional information
Non-streaming request
POST /chat/completions
Response includes:
"usage": {
"prompt_tokens": 72,
"completion_tokens": 8,
"total_tokens": 80
}
Streaming request with usage enabled
Request body includes:
{
"stream": true,
"stream_options": {
"include_usage": true
}
}
{
"choices": [],
"usage": {
"prompt_tokens": 72,
"completion_tokens": 8,
"total_tokens": 80
}
}
So the provider is not the problem, and the dashboard is not the primary problem either. The usage is being lost inside OpenClaw before persistence/display.
Additional Notes
Suspected Area
The issue appears to be in the openai-completions streaming path for OpenAI-compatible providers, especially handling of the final SSE chunk with:
{
"choices": [],
"usage": { ... }
}
Potentially relevant area:
Impact
This makes usage reporting effectively unusable for affected custom OpenAI-compatible providers:
Suggested Fix Direction