Missing stream_options parameter causes self-calculated usage instead of using model's native usage data in streaming mode #819

Closed
opened 2026-02-16 10:20:36 -05:00 by yindo · 1 comment
Owner

Originally created by @LycheeTown on GitHub (Nov 20, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues Dify issues & Dify Official Plugins, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.9.2

Plugin version

0.0.25

Cloud or Self Hosted

Self Hosted (Docker), Self Hosted (Source)

Steps to reproduce

Steps to reproduce

  1. Use either openai_api_compatible 0.0.25 or deepseek 0.0.7 plugin
  2. Enable streaming mode for LLM calls
  3. Observe that the plugins don't include the following parameter in model calls:
    model_parameters["stream_options"] = {"include_usage": True}
    
  4. As a result, the plugins calculate usage metrics themselves instead of using the model's native usage data

Expected behavior

Plugins should include the stream_options={"include_usage": True} parameter when making streaming calls to leverage the model's native usage reporting, rather than self-calculating these metrics.

Additional context

This affects both openai_api_compatible and deepseek plugins when operating in streaming mode. Adding this parameter would improve accuracy and consistency with how OpenAI and other compatible APIs report usage data during streaming responses.

✔️ Error log

No specific error logs, but the behavior leads to potentially inaccurate usage calculation as the plugins aren't leveraging the model's built-in usage reporting capabilities when in streaming mode.

Originally created by @LycheeTown on GitHub (Nov 20, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [Dify issues](https://github.com/langgenius/dify/issues) & [Dify Official Plugins](https://github.com/langgenius/dify-official-plugins/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.9.2 ### Plugin version 0.0.25 ### Cloud or Self Hosted Self Hosted (Docker), Self Hosted (Source) ### Steps to reproduce ## Steps to reproduce 1. Use either `openai_api_compatible 0.0.25` or `deepseek 0.0.7` plugin 2. Enable streaming mode for LLM calls 3. Observe that the plugins don't include the following parameter in model calls: ```python model_parameters["stream_options"] = {"include_usage": True} ``` 4. As a result, the plugins calculate usage metrics themselves instead of using the model's native usage data ## Expected behavior Plugins should include the `stream_options={"include_usage": True}` parameter when making streaming calls to leverage the model's native usage reporting, rather than self-calculating these metrics. ## Additional context This affects both `openai_api_compatible` and `deepseek` plugins when operating in streaming mode. Adding this parameter would improve accuracy and consistency with how OpenAI and other compatible APIs report usage data during streaming responses. ### ✔️ Error log No specific error logs, but the behavior leads to potentially inaccurate usage calculation as the plugins aren't leveraging the model's built-in usage reporting capabilities when in streaming mode.
yindo added the bug label 2026-02-16 10:20:36 -05:00
yindo closed this issue 2026-02-16 10:20:36 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Nov 20, 2025):

You're correct—both the openai_api_compatible and deepseek plugins currently do not set stream_options={"include_usage": True} in their streaming calls, which causes them to self-calculate usage metrics instead of using the model's native usage data. The base OpenAI-compatible plugin does set this parameter in streaming mode, but the specific plugins do not pass it along in their _invoke methods, leading to the issue you described (source, source).

To resolve this, you can modify the _invoke method in both plugins to add:

if stream:
    model_parameters["stream_options"] = {"include_usage": True}

before calling the superclass. This will ensure accurate usage reporting during streaming responses, matching the behavior of the base plugin.

No recent pull requests address this for these plugins, so a direct code change is currently the best workaround.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Nov 20, 2025): <!-- Answer --> You're correct—both the `openai_api_compatible` and `deepseek` plugins currently do not set `stream_options={"include_usage": True}` in their streaming calls, which causes them to self-calculate usage metrics instead of using the model's native usage data. The base OpenAI-compatible plugin does set this parameter in streaming mode, but the specific plugins do not pass it along in their `_invoke` methods, leading to the issue you described ([source](https://github.com/langgenius/dify-official-plugins/blob/edf201e349f8cd4b26cd4e8d002222d043fcbd66/models/openai_api_compatible/models/llm/llm.py#L121-L167), [source](https://github.com/langgenius/dify-official-plugins/blob/edf201e349f8cd4b26cd4e8d002222d043fcbd66/models/deepseek/models/llm/llm.py#L9-L34)). To resolve this, you can modify the `_invoke` method in both plugins to add: ```python if stream: model_parameters["stream_options"] = {"include_usage": True} ``` before calling the superclass. This will ensure accurate usage reporting during streaming responses, matching the behavior of the base plugin. No recent pull requests address this for these plugins, so a direct code change is currently the best workaround. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/141833af-9441-4c49-b8db-3e703e4494a5?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/141833af-9441-4c49-b8db-3e703e4494a5?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/141833af-9441-4c49-b8db-3e703e4494a5?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/141833af-9441-4c49-b8db-3e703e4494a5?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/141833af-9441-4c49-b8db-3e703e4494a5?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/141833af-9441-4c49-b8db-3e703e4494a5?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/141833af-9441-4c49-b8db-3e703e4494a5?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify-official-plugins/issues/2103)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-official-plugins#819