Skip to content

fix(server): populate OpenAI-compatible usage fields - #355

Open
mywonderland808 wants to merge 1 commit into
algorithmicsuperintelligence:mainfrom
mywonderland808:fix/openai-usage-reporting
Open

mywonderland808 wants to merge 1 commit into
algorithmicsuperintelligence:mainfrom
mywonderland808:fix/openai-usage-reporting

Conversation

@mywonderland808

Copy link
Copy Markdown

Summary

  • Fill prompt_tokens / total_tokens on approach-synthesized and passthrough chat completions (and batch / legacy /v1/completions), instead of omitting them or leaving prompt_tokens: 0.
  • Emit a final SSE usage chunk with choices: [] when stream_options.include_usage is set, matching OpenAI / existing dict-stream behavior.
  • Prefer real completion_tokens when known; estimate only when missing or zero with non-empty content. Includes focused unit and HTTP wiring tests.

Test plan

  • python -m unittest tests.test_usage_reporting -v
  • python -m unittest tests.test_completions_endpoint tests.test_proxy_plugin -v
  • Manual: non-stream approach response includes usage.prompt_tokens and usage.total_tokens
  • Manual: stream with stream_options.include_usage: true ends with a choices: [] usage chunk before [DONE]
  • Manual: passthrough/none response missing upstream prompt_tokens gets filled without clobbering complete upstream usage

Fill prompt_tokens/total_tokens on approach and passthrough responses, and
emit stream usage when stream_options.include_usage is set, so OpenAI-compatible
clients get a complete usage object instead of zeros or missing fields.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@mywonderland808

Copy link
Copy Markdown
Author

Hi! Before signing the CLA, I’d like to clarify one point regarding AI-assisted contributions.

This contribution was developed using Cursor (AI Agent) based on my own planning, architecture decisions, requirements, and instructions. The agent generated most of the implementation, which I subsequently reviewed and tested.

Cursor's terms grant me rights to the generated output.

Does this type of AI-assisted, agent-generated contribution comply with your Contributor License Agreement, particularly the representation that I am the sole author of the Contributions?

I'd appreciate your clarification before I sign the CLA.

Thanks!

This branch has not been deployed

No deployments
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.

2 participants