[GH-ISSUE #12395] when using cloud model ( Ollama Error: Invalid tool usage: mismatch between tool calls and tool results (status code: 400 ) #33993

Open
opened 2026-04-22 17:12:42 -05:00 by GiteaMirror · 9 comments
Owner

Originally created by @gbonobono on GitHub (Sep 24, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/12395

What is the issue?

Hello thanks for the great code

I am not sure if this issue is belong to your code, but
when I using cloud model, there is error like "Ollama Error: Invalid tool usage: mismatch between tool calls and tool results (status code: 400)"

would you please clarify if this issue is valid?
thanks

========================================================================================
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 🔧 Available Tools ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✓ mcp-server-commands.run_command │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 1/1 tools enabled ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭──────────────────────────────────────╮
🧠 Current model: gpt-oss:120b-cloud │
╰──────────────────────────────────────╯
gpt-oss/thinking/1-tool❯ 현재폴더에 어떤 파일이 있는지 알려줘

╭─ 🔧 Executing Tool mcp-server-commands.run_command ─╮
│ │
│ Arguments: │
│ │
│ │
│ { │
│ "command": "ls -la" │
│ } │
│ │
╰─────────────────────────────────────────────────────╯

🧑‍💻 Human-in-the-Loop Confirmation
Tool to execute: mcp-server-commands.run_command
Arguments:
• command: ls -la

Options:
y/yes - Execute the tool call
n/no - Skip this tool call
disable - Disable HIL confirmations permanently

What would you like to do? (y): y
Tip: Use 'human-in-loop' or 'hil' to disable these confirmations

╭───────── Tool Response mcp-server-commands.run_command ──────────╮
│ │
│ Arguments: │
│ │
│ │
│ { │
│ "command": "ls -la" │
│ } │
│ │
│ Response: │
│ │
│ │
│ total 20 │
│ drwxrwxr-x 3 ubuntu ubuntu 4096 Sep 24 14:25 . │
│ drwxr-x--- 32 ubuntu ubuntu 4096 Sep 24 14:25 .. │
│ drwxrwxr-x 8 ubuntu ubuntu 4096 Sep 24 10:37 mcp-server-commands │
│ -rw-rw-r-- 1 ubuntu ubuntu 123 Sep 24 10:39 server.json │
│ -rw-rw-r-- 1 ubuntu ubuntu 6 Sep 24 10:51 temp.txt │
│ │
│ │
╰───────────────────────���─────────────────────────────────────────────╯

⠦ working...
╭───────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Ollama Error: Invalid tool usage: mismatch between tool calls and tool results (status code: 400) │
╰───────────────────────────────────────────────────────────────────────────────────────────────────╯

Relevant log output


OS

No response

GPU

No response

CPU

No response

Ollama version

No response

Originally created by @gbonobono on GitHub (Sep 24, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/12395 ### What is the issue? Hello thanks for the great code I am not sure if this issue is belong to your code, but when I using cloud model, there is error like "Ollama Error: Invalid tool usage: mismatch between tool calls and tool results (status code: 400)" would you please clarify if this issue is valid? thanks ======================================================================================== ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 🔧 Available Tools ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ ✓ mcp-server-commands.run_command │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 1/1 tools enabled ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────╮ │ 🧠 Current model: gpt-oss:120b-cloud │ ╰──────────────────────────────────────╯ gpt-oss/thinking/1-tool❯ 현재폴더에 어떤 파일이 있는지 알려줘 ╭─ 🔧 Executing Tool mcp-server-commands.run_command ─╮ │ │ │ Arguments: │ │ │ │ │ │ { │ │ "command": "ls -la" │ │ } │ │ │ ╰─────────────────────────────────────────────────────╯ 🧑‍💻 Human-in-the-Loop Confirmation Tool to execute: mcp-server-commands.run_command Arguments: • command: ls -la Options: y/yes - Execute the tool call n/no - Skip this tool call disable - Disable HIL confirmations permanently What would you like to do? (y): y Tip: Use 'human-in-loop' or 'hil' to disable these confirmations ╭───────── ✅ Tool Response mcp-server-commands.run_command ──────────╮ │ │ │ Arguments: │ │ │ │ │ │ { │ │ "command": "ls -la" │ │ } │ │ │ │ Response: │ │ │ │ │ │ total 20 │ │ drwxrwxr-x 3 ubuntu ubuntu 4096 Sep 24 14:25 . │ │ drwxr-x--- 32 ubuntu ubuntu 4096 Sep 24 14:25 .. │ │ drwxrwxr-x 8 ubuntu ubuntu 4096 Sep 24 10:37 mcp-server-commands │ │ -rw-rw-r-- 1 ubuntu ubuntu 123 Sep 24 10:39 server.json │ │ -rw-rw-r-- 1 ubuntu ubuntu 6 Sep 24 10:51 temp.txt │ │ │ │ │ ╰───────────────────────���─────────────────────────────────────────────╯ ⠦ working... ╭───────────────────────────────────────────────────────────────────────────────────────────────────╮ │ Ollama Error: Invalid tool usage: mismatch between tool calls and tool results (status code: 400) │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────╯ ### Relevant log output ```shell ``` ### OS _No response_ ### GPU _No response_ ### CPU _No response_ ### Ollama version _No response_
GiteaMirror added the cloudbug labels 2026-04-22 17:12:42 -05:00
Author
Owner

@naknak987 commented on GitHub (Sep 24, 2025):

I also receive this error when using qwen3-coder:480b-cloud.

{"error": "Invalid tool usage: mismatch between tool calls and tool results"}

<!-- gh-comment-id:3330694133 --> @naknak987 commented on GitHub (Sep 24, 2025): I also receive this error when using `qwen3-coder:480b-cloud`. > {"error": "Invalid tool usage: mismatch between tool calls and tool results"}
Author
Owner

@it-nalon commented on GitHub (Sep 27, 2025):

Hi, I had the same issue and discovered I was sending a tool_call that wasn't declared in the tools array.

I was doing this:

{
  "model": "deepseek-v3.1:671b",
  "messages": [
    {
      "role": "assistant",
      "content": "",
      "tool_calls": [
        {
          "function": {
            "name": "other_agent_tool_call",
            "arguments": {
              ...
            }
          }
        }
      ]
    },
    {
      "role": "user",
      "content": "Provide a concise update on the status based on your last message"
    }
  ],
  "stream": true,
  "tools": [] // <- other_agent_tool_call does not exist here
}

I fixed it by sending a transcript of the message instead of a raw json:

{
  "model": "deepseek-v3.1:671b",
  "messages": [
    {
      "role": "user",
      "content": "Last events:\n[assistant] Tool call: { ... }"
    },
    {
      "role": "user",
      "content": "Provide a concise update on the status based on the last events"
    }
  ],
  "stream": true,
  "tools": []
}

Maybe you're having a similar issue?

<!-- gh-comment-id:3341883537 --> @it-nalon commented on GitHub (Sep 27, 2025): Hi, I had the same issue and discovered I was sending a `tool_call` that wasn't declared in the `tools` array. I was doing this: ``` { "model": "deepseek-v3.1:671b", "messages": [ { "role": "assistant", "content": "", "tool_calls": [ { "function": { "name": "other_agent_tool_call", "arguments": { ... } } } ] }, { "role": "user", "content": "Provide a concise update on the status based on your last message" } ], "stream": true, "tools": [] // <- other_agent_tool_call does not exist here } ``` I fixed it by sending a transcript of the message instead of a raw json: ``` { "model": "deepseek-v3.1:671b", "messages": [ { "role": "user", "content": "Last events:\n[assistant] Tool call: { ... }" }, { "role": "user", "content": "Provide a concise update on the status based on the last events" } ], "stream": true, "tools": [] } ``` Maybe you're having a similar issue?
Author
Owner

@gbonobono commented on GitHub (Sep 28, 2025):

Hi , the deepseek-v3.1:671b was cloud model?

<!-- gh-comment-id:3342179537 --> @gbonobono commented on GitHub (Sep 28, 2025): Hi , the deepseek-v3.1:671b was cloud model?
Author
Owner

@it-nalon commented on GitHub (Sep 30, 2025):

Yes, I tried both in the local environment and in the cloud one (ollama.com/api), same behavior.

<!-- gh-comment-id:3350160201 --> @it-nalon commented on GitHub (Sep 30, 2025): Yes, I tried both in the local environment and in the cloud one (`ollama.com/api`), same behavior.
Author
Owner

@matscalia commented on GitHub (Oct 13, 2025):

yes, it happens with opencode too

<!-- gh-comment-id:3397208989 --> @matscalia commented on GitHub (Oct 13, 2025): yes, it happens with opencode too
Author
Owner

@Emmanuel-Odebiyi commented on GitHub (Oct 14, 2025):

@gbonobono I also had same issue but I found out that it is not all cloud model of ollama actually supports tool calling, so I changed my former model ( gpt-oss:20b-cloud) into another one (gpt-oss:120b-cloud) and that solves the issue, I hope this helps.

<!-- gh-comment-id:3401027986 --> @Emmanuel-Odebiyi commented on GitHub (Oct 14, 2025): @gbonobono I also had same issue but I found out that it is not all cloud model of ollama actually supports tool calling, so I changed my former model ( gpt-oss:20b-cloud) into another one (gpt-oss:120b-cloud) and that solves the issue, I hope this helps.
Author
Owner

@bitbytebit1 commented on GitHub (Oct 15, 2025):

For me the issue was not pushing the call request onto the message history, this immediately resolved the issue

<!-- gh-comment-id:3407980796 --> @bitbytebit1 commented on GitHub (Oct 15, 2025): For me the issue was not pushing the call request onto the message history, this immediately resolved the issue
Author
Owner

@jonigl commented on GitHub (Oct 20, 2025):

Hi everyone! I got it fixed and working for jonigl/mcp-client-for-ollama since v0.19.0.
However, I noticed that deepseek-v3.1:671b-cloud doesn’t seem to handle tool calls correctly. Tool calls aren’t being parsed as expected. I’ll share a screenshot to illustrate the issue. (I have opened I new issue just in case https://github.com/ollama/ollama/issues/12702)

Image
<!-- gh-comment-id:3421266789 --> @jonigl commented on GitHub (Oct 20, 2025): Hi everyone! I got it fixed and working for [jonigl/mcp-client-for-ollama](https://github.com/jonigl/mcp-client-for-ollama) since **v0.19.0**. However, I noticed that `deepseek-v3.1:671b-cloud` doesn’t seem to handle tool calls correctly. Tool calls aren’t being parsed as expected. I’ll share a screenshot to illustrate the issue. (I have opened I new issue just in case https://github.com/ollama/ollama/issues/12702) <img width="1421" height="185" alt="Image" src="https://github.com/user-attachments/assets/a9a4f0b7-b567-4e7d-9e5c-4300b31d0031" />
Author
Owner

@ParthSareen commented on GitHub (Nov 8, 2025):

Hi y'all. This error message pops up when there isn't a subsequent message with role tool after a message with tool_calls. The tool call the model made also needs to be sent to the model

<!-- gh-comment-id:3505541693 --> @ParthSareen commented on GitHub (Nov 8, 2025): Hi y'all. This error message pops up when there isn't a subsequent message with role `tool` after a message with `tool_calls`. The tool call the model made also needs to be sent to the model
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#33993