[GH-ISSUE #19390] issue: tools will double the token cost #57521

Closed
opened 2026-05-05 21:01:46 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @FujinoXiao on GitHub (Nov 23, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/19390

Check Existing Issues

  • I have searched for any existing and/or related issues.
  • I have searched for any existing and/or related discussions.
  • I have also searched in the CLOSED issues AND CLOSED discussions and found no related items (your issue might already be addressed on the development branch!).
  • I am using the latest version of Open WebUI.

Installation Method

Git Clone

Open WebUI Version

latest

Ollama Version (if applicable)

No response

Operating System

ubuntu22.04

Browser (if applicable)

No response

Confirmation

  • I have read and followed all instructions in README.md.
  • I am using the latest version of both Open WebUI and Ollama.
  • I have included the browser console logs.
  • I have included the Docker container logs.
  • I have provided every relevant configuration, setting, and environment variable used in my setup.
  • I have clearly listed every relevant configuration, custom setting, environment variable, and command-line option that influences my setup (such as Docker Compose overrides, .env values, browser settings, authentication configurations, etc).
  • I have documented step-by-step reproduction instructions that are precise, sequential, and leave nothing to interpretation. My steps:
  • Start with the initial platform/version/OS and dependencies used,
  • Specify exact install/launch/configure commands,
  • List URLs visited, user input (incl. example values/emails/passwords if needed),
  • Describe all options and toggles enabled or changed,
  • Include any files or environmental changes,
  • Identify the expected and actual result at each stage,
  • Ensure any reasonably skilled user can follow and hit the same issue.

Expected Behavior

if using tools,and tools cost 5000 token ,it should cost 5000 token

but the cost is double

Actual Behavior

the token cost thought tools is double

Steps to Reproduce

1.use any kind of tools (better use larger tools,it will be more clear)
2.check the prompt cost,it is unusual

Logs & Screenshots

2025-11-21 04:48:12.088 | INFO | open_webui.utils.chat:generate_chat_completion:183 - Message 1 (user): {
"role": "user",
"content": "

<source id="1" name="server:5/search_huadai20_api_v1_huadai20_search_post">
{
"documents": [{
"file_content": "完整报告内容(第1次出现)"
}]
}

<user_query>
搜索1条 胶原蛋白I型文档
</user_query>

搜索1条 胶原蛋白I型文档

Tool `server:5/search_huadai20_api_v1_huadai20_search_post` Output: {
  \"documents\": [{
    \"file_content\": \"完整报告内容(第2次出现,完全相同)\"
  }]
}

"
}


i use my own log to debug the question and the reason is when you are using tools the context using the tools resut l also the tools result ,so it double the token

the problem is in the code

`open-webui/backend/open_webui/utils/middleware.py`

when using tools the result and toos will be add twice


### Additional Information

_No response_
Originally created by @FujinoXiao on GitHub (Nov 23, 2025). Original GitHub issue: https://github.com/open-webui/open-webui/issues/19390 ### Check Existing Issues - [x] I have searched for any existing and/or related issues. - [x] I have searched for any existing and/or related discussions. - [x] I have also searched in the CLOSED issues AND CLOSED discussions and found no related items (your issue might already be addressed on the development branch!). - [x] I am using the latest version of Open WebUI. ### Installation Method Git Clone ### Open WebUI Version latest ### Ollama Version (if applicable) _No response_ ### Operating System ubuntu22.04 ### Browser (if applicable) _No response_ ### Confirmation - [x] I have read and followed all instructions in `README.md`. - [x] I am using the latest version of **both** Open WebUI and Ollama. - [x] I have included the browser console logs. - [x] I have included the Docker container logs. - [x] I have **provided every relevant configuration, setting, and environment variable used in my setup.** - [x] I have clearly **listed every relevant configuration, custom setting, environment variable, and command-line option that influences my setup** (such as Docker Compose overrides, .env values, browser settings, authentication configurations, etc). - [x] I have documented **step-by-step reproduction instructions that are precise, sequential, and leave nothing to interpretation**. My steps: - Start with the initial platform/version/OS and dependencies used, - Specify exact install/launch/configure commands, - List URLs visited, user input (incl. example values/emails/passwords if needed), - Describe all options and toggles enabled or changed, - Include any files or environmental changes, - Identify the expected and actual result at each stage, - Ensure any reasonably skilled user can follow and hit the same issue. ### Expected Behavior if using tools,and tools cost 5000 token ,it should cost 5000 token but the cost is double ### Actual Behavior the token cost thought tools is double ### Steps to Reproduce 1.use any kind of tools (better use larger tools,it will be more clear) 2.check the prompt cost,it is unusual ### Logs & Screenshots 2025-11-21 04:48:12.088 | INFO | open_webui.utils.chat:generate_chat_completion:183 - Message 1 (user): { "role": "user", "content": " <context> <source id=\"1\" name=\"server:5/search_huadai20_api_v1_huadai20_search_post\"> { \"documents\": [{ \"file_content\": \"完整报告内容(第1次出现)\" }] } </source> </context> <user_query> 搜索1条 胶原蛋白I型文档 </user_query> 搜索1条 胶原蛋白I型文档 Tool `server:5/search_huadai20_api_v1_huadai20_search_post` Output: { \"documents\": [{ \"file_content\": \"完整报告内容(第2次出现,完全相同)\" }] } " } ``` i use my own log to debug the question and the reason is when you are using tools the context using the tools resut l also the tools result ,so it double the token the problem is in the code `open-webui/backend/open_webui/utils/middleware.py` when using tools the result and toos will be add twice ### Additional Information _No response_
GiteaMirror added the bug label 2026-05-05 21:01:46 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#57521