Chatflow Token Statistics Showing Zero #781

Closed
opened 2026-02-16 10:20:29 -05:00 by yindo · 4 comments
Owner

Originally created by @Shaoqi-Cen on GitHub (Nov 6, 2025).

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.9.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Chatflow applications are showing incorrect token usage statistics, with all token counts displaying as 0 regardless of actual model usage. This prevents accurate usage monitoring and billing calculations.

  1. Create a new Chatflow application
  2. Add an LLM node and configure any model (e.g., GPT-4, Claude, etc.)
  3. Publish the application and conduct multiple conversation rounds
  4. Check the token usage statistics in the application monitor page

chatflow example:
Image

agent example:

Image

✔️ Expected Behavior

  • Should correctly track and display actual token usage
  • Include accurate counts for both input and output tokens
  • Calculate usage costs correctly based on model pricing
  • Display accurate data in both application overview and tenant statistics

Actual Behavior

  • Token usage displays as 0
  • Cost statistics show 0
  • Unable to accurately track actual model invocation costs
Image
Originally created by @Shaoqi-Cen on GitHub (Nov 6, 2025). ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [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 [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report, otherwise it will be closed. - [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.9.1 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce Chatflow applications are showing incorrect token usage statistics, with all token counts displaying as 0 regardless of actual model usage. This prevents accurate usage monitoring and billing calculations. 1. Create a new Chatflow application 2. Add an LLM node and configure any model (e.g., GPT-4, Claude, etc.) 3. Publish the application and conduct multiple conversation rounds 4. Check the token usage statistics in the application monitor page chatflow example: <img width="1877" height="945" alt="Image" src="https://github.com/user-attachments/assets/25613ace-2d1e-43ad-a651-0cdc8589a1a1" /> agent example: <img width="1915" height="1000" alt="Image" src="https://github.com/user-attachments/assets/f278a05e-fdc6-4f5c-83e5-397e09d625c3" /> ### ✔️ Expected Behavior - Should correctly track and display actual token usage - Include accurate counts for both input and output tokens - Calculate usage costs correctly based on model pricing - Display accurate data in both application overview and tenant statistics ### ❌ Actual Behavior - Token usage displays as 0 - Cost statistics show 0 - Unable to accurately track actual model invocation costs <img width="745" height="508" alt="Image" src="https://github.com/user-attachments/assets/2536a904-8cde-4ed5-bbdc-d0995951e2db" />
yindo added the bug label 2026-02-16 10:20:29 -05:00
yindo closed this issue 2026-02-16 10:20:29 -05:00
Author
Owner

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

Hi @Shaoqi-Cen! I'm Dosu and I’m helping the dify team.

This is a known bug in Dify v1.9.1 (self-hosted, Docker): Chatflow token usage and cost statistics show zero because the backend summary API omits token fields like answer_tokens and message_tokens in conversation summaries, even though the backend calculates them correctly for detailed views. The frontend dashboard relies on these missing fields, so it displays zeros. This issue was introduced between v1.8 and v1.9.1 and is fixed by updating the backend summary serialization to include the missing token fields—no configuration or migration is needed, just a code-level fix. The fix was merged in PR langgenius/dify#26723 and released in v1.9.2, but some edge cases may persist in certain agent policies or plugin setups [source].

Workarounds: You can still see correct token usage in the detailed log view, even if the main table shows zero. For plugin-based or custom models, ensure the model/plugin supplies usage data and that any required flags (like PLUGIN_BASED_TOKEN_COUNTING_ENABLED) are set. For some models (like vllm), the request must include stream_options: { "include_usage": true } or usage will always be zero [source].

To resolve: Upgrade to v1.9.2 or later, or patch your backend to include the missing token fields in the summary API response. If you continue to see zeros after upgrading, check your model/plugin integration and logs for errors during token extraction.

To reply, just mention @dosu.


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

@dosubot[bot] commented on GitHub (Nov 6, 2025): <!-- Greeting --> Hi @Shaoqi-Cen! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the dify team. <!-- Answer --> This is a known bug in Dify v1.9.1 (self-hosted, Docker): Chatflow token usage and cost statistics show zero because the backend summary API omits token fields like `answer_tokens` and `message_tokens` in conversation summaries, even though the backend calculates them correctly for detailed views. The frontend dashboard relies on these missing fields, so it displays zeros. This issue was introduced between v1.8 and v1.9.1 and is fixed by updating the backend summary serialization to include the missing token fields—no configuration or migration is needed, just a code-level fix. The fix was merged in PR langgenius/dify#26723 and released in v1.9.2, but some edge cases may persist in certain agent policies or plugin setups [[source]](https://github.com/langgenius/dify/issues/27590). Workarounds: You can still see correct token usage in the detailed log view, even if the main table shows zero. For plugin-based or custom models, ensure the model/plugin supplies usage data and that any required flags (like `PLUGIN_BASED_TOKEN_COUNTING_ENABLED`) are set. For some models (like vllm), the request must include `stream_options: { "include_usage": true }` or usage will always be zero [[source]](https://github.com/langgenius/dify/issues/26086). To resolve: Upgrade to v1.9.2 or later, or patch your backend to include the missing token fields in the summary API response. If you continue to see zeros after upgrading, check your model/plugin integration and logs for errors during token extraction. <!-- 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/60db59ec-c104-43e6-be5a-a03d0cd07e3f?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/60db59ec-c104-43e6-be5a-a03d0cd07e3f?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/60db59ec-c104-43e6-be5a-a03d0cd07e3f?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/60db59ec-c104-43e6-be5a-a03d0cd07e3f?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/60db59ec-c104-43e6-be5a-a03d0cd07e3f?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/60db59ec-c104-43e6-be5a-a03d0cd07e3f?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/60db59ec-c104-43e6-be5a-a03d0cd07e3f?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&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/issues/27921)
Author
Owner

@Shaoqi-Cen commented on GitHub (Nov 6, 2025):

@dosu This doesn't seem to be the same issue. In my postgresql tables messages and workflow_runs, the token counts are both showing as 0. I’ll try enabling PLUGIN_BASED_TOKEN_COUNTING_ENABLED and will report back here with any findings.

Image Image
@Shaoqi-Cen commented on GitHub (Nov 6, 2025): [@dosu](https://go.dosu.dev/dosubot) This doesn't seem to be the same issue. In my postgresql tables messages and workflow_runs, the token counts are both showing as 0. I’ll try enabling PLUGIN_BASED_TOKEN_COUNTING_ENABLED and will report back here with any findings. <img width="745" height="508" alt="Image" src="https://github.com/user-attachments/assets/a6276419-411c-42ea-90f5-1bfa75abd1ba" /> <img width="652" height="528" alt="Image" src="https://github.com/user-attachments/assets/3c771666-bd52-4d84-9038-6ef3721a1a07" />
Author
Owner

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

You're right—this isn't just a frontend/API serialization bug. If your messages and workflow_runs tables are showing zero token counts, the issue is deeper in the workflow execution or token counting logic.

Common causes: the workflow may not be reaching the LLM invocation step (due to moderation stops, validation, or early exits), or the model/plugin isn't returning usage data, so Dify falls back to zero tokens in the database. For plugin-based or custom models, enabling PLUGIN_BASED_TOKEN_COUNTING_ENABLED is required, but for standard LLM nodes (like GPT-4, Claude), this flag doesn't affect token counting—they rely on built-in provider logic. If the provider/model doesn't supply usage info, or if the workflow fails before the LLM runs, you'll see zeros persisted [source].

For some models (especially vllm), you must include stream_options: { "include_usage": true } in the request, or usage will always be zero—even if the LLM returns output [source]. If you see repeated <think> placeholders or empty token fields, it's likely the workflow isn't reaching the LLM step or the plugin/model isn't reporting usage.

Recent code changes (merged after v1.9.1) improved token usage accumulation in workflow event handlers, so upgrading to v1.9.2+ may help if your issue is related to missed usage in streaming workflows [source].

Troubleshooting steps: check your workflow logs to confirm the LLM node is executed and returns usage data, verify your model/plugin integration, and ensure your configuration enables token counting. If you continue to see zeros, inspect logs for errors during token extraction or workflow execution. If you're using custom models or plugins, make sure they're updated to support usage reporting.

To reply, just mention @dosu.


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

@dosubot[bot] commented on GitHub (Nov 6, 2025): <!-- Answer --> You're right—this isn't just a frontend/API serialization bug. If your messages and workflow_runs tables are showing zero token counts, the issue is deeper in the workflow execution or token counting logic. Common causes: the workflow may not be reaching the LLM invocation step (due to moderation stops, validation, or early exits), or the model/plugin isn't returning usage data, so Dify falls back to zero tokens in the database. For plugin-based or custom models, enabling `PLUGIN_BASED_TOKEN_COUNTING_ENABLED` is required, but for standard LLM nodes (like GPT-4, Claude), this flag doesn't affect token counting—they rely on built-in provider logic. If the provider/model doesn't supply usage info, or if the workflow fails before the LLM runs, you'll see zeros persisted [[source]](https://github.com/langgenius/dify/issues/26086). For some models (especially vllm), you must include `stream_options: { "include_usage": true }` in the request, or usage will always be zero—even if the LLM returns output [[source]](https://github.com/langgenius/dify/issues/20796). If you see repeated `<think>` placeholders or empty token fields, it's likely the workflow isn't reaching the LLM step or the plugin/model isn't reporting usage. Recent code changes (merged after v1.9.1) improved token usage accumulation in workflow event handlers, so upgrading to v1.9.2+ may help if your issue is related to missed usage in streaming workflows [[source]](https://github.com/langgenius/dify/pull/26723). Troubleshooting steps: check your workflow logs to confirm the LLM node is executed and returns usage data, verify your model/plugin integration, and ensure your configuration enables token counting. If you continue to see zeros, inspect logs for errors during token extraction or workflow execution. If you're using custom models or plugins, make sure they're updated to support usage reporting. <!-- 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/54b6ad8e-359d-4c99-b979-e0a959942684?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/54b6ad8e-359d-4c99-b979-e0a959942684?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/54b6ad8e-359d-4c99-b979-e0a959942684?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/54b6ad8e-359d-4c99-b979-e0a959942684?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/54b6ad8e-359d-4c99-b979-e0a959942684?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/54b6ad8e-359d-4c99-b979-e0a959942684?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/54b6ad8e-359d-4c99-b979-e0a959942684?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&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/issues/27921)
Author
Owner

@Shaoqi-Cen commented on GitHub (Nov 10, 2025):

Enabling PLUGIN_BASED_TOKEN_COUNTING_ENABLED didn't resolve the issue, but upgrading to version 1.9.2 did. Thank you very much for your response!

@Shaoqi-Cen commented on GitHub (Nov 10, 2025): Enabling `PLUGIN_BASED_TOKEN_COUNTING_ENABLED` didn't resolve the issue, but upgrading to version **1.9.2** did. Thank you very much for your response!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-official-plugins#781