Skip to content

fix: some completion providers send usage chunks with 0 completion choices causing 0 reported usage#1211

Merged
joshua-mo-143 merged 2 commits into0xPlaygrounds:mainfrom
dxvid-pts:usage_bug_fix
Jan 6, 2026
Merged

fix: some completion providers send usage chunks with 0 completion choices causing 0 reported usage#1211
joshua-mo-143 merged 2 commits into0xPlaygrounds:mainfrom
dxvid-pts:usage_bug_fix

Conversation

@dxvid-pts
Copy link
Copy Markdown
Contributor

@dxvid-pts dxvid-pts commented Jan 4, 2026

Fixes: #1212

Proposed fix:

  • In rig-core/src/providers/openai/completion/streaming.rs, capture data.usage before the choices.first() early-continue, e.g.

    if let Some(usage) = data.usage.as_ref() {
    final_usage = Some(usage.clone());
    }

  • Add regression test: deserialize a chunk with choices: [] and usage != null and ensure the final streamed usage is not lost.

@dxvid-pts dxvid-pts changed the title fix usage report bein 0 fix usage report being 0 Jan 5, 2026
@dxvid-pts
Copy link
Copy Markdown
Contributor Author

pipeline should be fixed now

Copy link
Copy Markdown
Contributor

@joshua-mo-143 joshua-mo-143 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm. Thanks for adding the additional test

@joshua-mo-143 joshua-mo-143 added this pull request to the merge queue Jan 6, 2026
@joshua-mo-143 joshua-mo-143 removed this pull request from the merge queue due to a manual request Jan 6, 2026
@joshua-mo-143 joshua-mo-143 changed the title fix usage report being 0 fix: some completion providers send usage chunks with 0 completion choices causing 0 reported usage Jan 6, 2026
@joshua-mo-143 joshua-mo-143 added this pull request to the merge queue Jan 6, 2026
Merged via the queue into 0xPlaygrounds:main with commit 3fe7025 Jan 6, 2026
5 checks passed
@github-actions github-actions Bot mentioned this pull request Jan 6, 2026
ThomasMarches pushed a commit to ThomasMarches/rig that referenced this pull request Feb 13, 2026
…oices causing 0 reported usage (0xPlaygrounds#1211)

* fix

* clippy and fmt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: token usage always 0 for streaming OpenAI Chat Completions for some providers

2 participants