Skip to content

Usage statistics not recorded when upstream returns 0 tokens #2273

@LucasInsight

Description

@LucasInsight

Describe the bug

When an upstream model API returns a successful response but explicitly sets all token usage metrics to 0 (e.g., "total_tokens": 0), the request is entirely excluded from CLIProxyAPI's usage statistics aggregation.

While it is correct to filter out empty chunks from streams to prevent spam, a completed request that happens to report 0 tokens should still be recorded as a valid request/transaction in the usage statistics (so the request count increments), rather than being silently dropped.

Steps to reproduce

  1. Configure a provider that returns "usage": {"prompt_tokens": 0, "completion_tokens": 0, "total_tokens": 0} in its successful JSON response.
  2. Enable usage-statistics-enabled: true in the config.
  3. Make a chat completion request to this model.
  4. Observe that the token/request usage in the management dashboard remains unchanged for this key/model.

Expected behavior

The request should be recorded in the in-memory usage statistics (incrementing the request count) even if the token delta is 0.

Related PR

A fix for this has been submitted in PR #2272, which adds the missing ensurePublished safety calls to the affected executors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions