Skip to content

[Bug]: OpenAI-compatible custom providers lose streaming usage data, causing zero session tokens and unknown dashboard usage #49753

@SvenM87

Description

@SvenM87

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

  1. Configure a custom provider using api: "openai-completions".
  2. Use that provider for an agent.
  3. Send a simple prompt, for example:

openclaw agent --agent main --message "Reply with exactly OK."

  1. Check usage status:

openclaw status --usage

  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingbug:behaviorIncorrect behavior without a crash

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions