[PR #1798] Fix/OpenAI streaming usage #2094

Open
opened 2026-02-16 11:16:05 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langgenius/dify-official-plugins/pull/1798
Author: @Arui1122
Created: 10/1/2025
Status: 🔄 Open

Base: mainHead: fix/openai-streaming-usage


📝 Commits (2)

  • 1eea78e fix(openai_api_compatible): include usage in streaming responses
  • 232ca01 chore: bump version to 0.0.23

📊 Changes

2 files changed (+126 additions, -2 deletions)

View changed files

📝 models/openai_api_compatible/manifest.yaml (+1 -1)
📝 models/openai_api_compatible/models/llm/llm.py (+125 -1)

📄 Description

Related Issues or Context

Fixes token counting issue for OpenAI-compatible APIs in streaming mode.

OpenAI-compatible providers (like LiteLLM) do not return token usage by default in streaming responses. This causes Dify to fall back to token estimation instead of using the actual count from the provider.

This PR contains Changes to Non-Plugin

  • Documentation
  • Other

This PR contains Changes to Non-LLM Models Plugin

  • I have Run Comprehensive Tests Relevant to My Changes

This PR contains Changes to LLM Models Plugin

  • My Changes Affect Message Flow Handling (System Messages and User→Assistant Turn-Taking)

  • My Changes Affect Tool Interaction Flow (Multi-Round Usage and Output Handling, for both Agent App and Agent Node)

  • My Changes Affect Multimodal Input Handling (Images, PDFs, Audio, Video, etc.)

  • My Changes Affect Multimodal Output Generation (Images, Audio, Video, etc.)

  • My Changes Affect Structured Output Format (JSON, XML, etc.)

  • My Changes Affect Token Consumption Metrics

  • My Changes Affect Other LLM Functionalities (Reasoning Process, Grounding, Prompt Caching, etc.)

  • Other Changes (Add New Models, Fix Model Parameters etc.)

Version Control

  • I have Bumped Up the Version in Manifest.yaml (Top-Level Version Field, Not in Meta Section)

Dify Plugin SDK Version

  • I have Ensured dify_plugin>=0.3.0,<0.5.0 is in requirements.txt (SDK docs)

Environment Verification

Local Deployment Environment

  • Dify Version is: 1.7.1, I have Tested My Changes on Local Deployment Dify with a Clean Environment That Matches the Production Configuration.

SaaS Environment

  • I have Tested My Changes on cloud.dify.ai with a Clean Environment That Matches the Production Configuration

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langgenius/dify-official-plugins/pull/1798 **Author:** [@Arui1122](https://github.com/Arui1122) **Created:** 10/1/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/openai-streaming-usage` --- ### 📝 Commits (2) - [`1eea78e`](https://github.com/langgenius/dify-official-plugins/commit/1eea78e886ca9a3c12ce85cdfcbe3176734e82fe) fix(openai_api_compatible): include usage in streaming responses - [`232ca01`](https://github.com/langgenius/dify-official-plugins/commit/232ca01498d66a712f8a8199bad2779c0e3f86f6) chore: bump version to 0.0.23 ### 📊 Changes **2 files changed** (+126 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `models/openai_api_compatible/manifest.yaml` (+1 -1) 📝 `models/openai_api_compatible/models/llm/llm.py` (+125 -1) </details> ### 📄 Description ## Related Issues or Context Fixes token counting issue for OpenAI-compatible APIs in streaming mode. OpenAI-compatible providers (like LiteLLM) do not return token usage by default in streaming responses. This causes Dify to fall back to token estimation instead of using the actual count from the provider. ## This PR contains Changes to *Non-Plugin* - [ ] Documentation - [ ] Other ## This PR contains Changes to *Non-LLM Models Plugin* - [ ] I have Run Comprehensive Tests Relevant to My Changes ## This PR contains Changes to *LLM Models Plugin* - [ ] My Changes Affect Message Flow Handling (System Messages and User→Assistant Turn-Taking) - [ ] My Changes Affect Tool Interaction Flow (Multi-Round Usage and Output Handling, for both Agent App and Agent Node) - [ ] My Changes Affect Multimodal Input Handling (Images, PDFs, Audio, Video, etc.) - [ ] My Changes Affect Multimodal Output Generation (Images, Audio, Video, etc.) - [ ] My Changes Affect Structured Output Format (JSON, XML, etc.) - [x] My Changes Affect Token Consumption Metrics - [ ] My Changes Affect Other LLM Functionalities (Reasoning Process, Grounding, Prompt Caching, etc.) - [ ] Other Changes (Add New Models, Fix Model Parameters etc.) ## Version Control - [x] I have Bumped Up the Version in Manifest.yaml (Top-Level `Version` Field, Not in Meta Section) ## Dify Plugin SDK Version - [x] I have Ensured `dify_plugin>=0.3.0,<0.5.0` is in requirements.txt ([SDK docs](https://github.com/langgenius/dify-plugin-sdks/blob/main/python/README.md)) ## Environment Verification ### Local Deployment Environment - [x] Dify Version is: 1.7.1, I have Tested My Changes on Local Deployment Dify with a Clean Environment That Matches the Production Configuration. ### SaaS Environment - [ ] I have Tested My Changes on cloud.dify.ai with a Clean Environment That Matches the Production Configuration --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 11:16:05 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-official-plugins#2094