mirror of
https://github.com/langgenius/dify-official-plugins.git
synced 2026-07-22 01:55:27 -04:00
Chatflow Token Statistics Showing Zero #781
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Shaoqi-Cen on GitHub (Nov 6, 2025).
Self Checks
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.
chatflow example:

agent example:
✔️ Expected Behavior
❌ Actual Behavior
@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_tokensandmessage_tokensin 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 includestream_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

@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.
@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_ENABLEDis 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

@Shaoqi-Cen commented on GitHub (Nov 10, 2025):
Enabling
PLUGIN_BASED_TOKEN_COUNTING_ENABLEDdidn't resolve the issue, but upgrading to version 1.9.2 did. Thank you very much for your response!