Skip to content

fix(proxy): capture streaming token usage for Ollama providers#1592

Merged
SebConejo merged 1 commit intomainfrom
docker-numbers
Apr 16, 2026
Merged

fix(proxy): capture streaming token usage for Ollama providers#1592
SebConejo merged 1 commit intomainfrom
docker-numbers

Conversation

@SebConejo
Copy link
Copy Markdown
Member

@SebConejo SebConejo commented Apr 16, 2026

Summary

  • Inject stream_options.include_usage: true for ollama and ollama-cloud endpoints in streaming requests, matching the existing behavior for openai and openrouter
  • Without this flag, Ollama servers omit token usage data from the final SSE chunk, resulting in 0 tokens and $0.00 costs in the dashboard
  • Add test coverage for both Ollama variants

Closes #1585


Summary by cubic

Fix missing token usage in streaming responses from ollama and ollama-cloud by injecting stream_options.include_usage, matching openai/openrouter. Restores accurate token counts and costs in the dashboard. Closes #1585.

  • Bug Fixes
    • Inject stream_options.include_usage: true for streaming requests to ollama and ollama-cloud.
    • Added tests to assert the injection for both providers.

Written for commit aa004e3. Summary will update on new commits.

Ollama and Ollama Cloud streaming responses returned 0 tokens because
they require stream_options.include_usage to emit usage data in the
final SSE chunk. Extend the existing injection (added for OpenAI and
OpenRouter in #1567) to cover ollama and ollama-cloud endpoint keys.

Closes #1585
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.92%. Comparing base (67f8852) to head (aa004e3).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1592   +/-   ##
=======================================
  Coverage   97.92%   97.92%           
=======================================
  Files         118      118           
  Lines        8675     8675           
  Branches     3265     3265           
=======================================
  Hits         8495     8495           
  Misses        178      178           
  Partials        2        2           
Flag Coverage Δ
frontend 97.91% <ø> (ø)
shared 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

@SebConejo SebConejo merged commit aeb7a54 into main Apr 16, 2026
15 checks passed
@SebConejo SebConejo deleted the docker-numbers branch April 16, 2026 22:34
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.

Using Ollama Cloud, and still see all zeros in manifest for token counts.

1 participant