Kimi-K2 via OpenRouter fails with tool call tokens inside thinking block #6453

Open
opened 2026-02-16 18:04:16 -05:00 by yindo · 6 comments
Owner

Originally created by @graham33 on GitHub (Jan 16, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

When using Kimi-K2 via OpenRouter with a recent OpenCode (1.1.21), I see tool call tokens in thinking sections, and the tool stops before I get a useful response.

kimi-k2-session.txt

Plugins

No response

OpenCode version

1.1.21

Steps to reproduce

Given the following prompt:

what is the tech stack of this project?

I get this thinking output in the UI:

Thinking: I'll analyze the tech stack of this project by examining the configuration files and codebase structure. <|tool_calls_section_begin|> <|tool_call_begin|> functions.bash:0 <|tool_call_argument_begin|> {"command": "ls -la", "description": "List files in current directory"} <|tool_call_end|> <|tool_call_begin|> functions.glob:1 <|tool_call_argument_begin|> {"pattern": "/.json"} <|tool_call_end|> <|tool_call_begin|> functions.glob:2 <|tool_call_argument_begin|> {"pattern": "/.{js,ts,jsx,tsx}"} <|tool_call_end|> <|tool_call_begin|> functions.glob:3 <|tool_call_argument_begin|> {"pattern": "/*.{py,java,go,rs,c,cpp}"} <|tool_call_end|> <|tool_calls_section_end|

Screenshot and/or share link

Image

Operating System

NixOS unstable

Terminal

kitty

Originally created by @graham33 on GitHub (Jan 16, 2026). Originally assigned to: @rekram1-node on GitHub. ### Description When using Kimi-K2 via OpenRouter with a recent OpenCode (1.1.21), I see tool call tokens in thinking sections, and the tool stops before I get a useful response. [kimi-k2-session.txt](https://github.com/user-attachments/files/24667438/kimi-k2-session.txt) ### Plugins _No response_ ### OpenCode version 1.1.21 ### Steps to reproduce Given the following prompt: > what is the tech stack of this project? I get this thinking output in the UI: > Thinking: I'll analyze the tech stack of this project by examining the configuration files and codebase structure. <|tool_calls_section_begin|> <|tool_call_begin|> functions.bash:0 <|tool_call_argument_begin|> {"command": "ls -la", "description": "List files in current directory"} <|tool_call_end|> <|tool_call_begin|> functions.glob:1 <|tool_call_argument_begin|> {"pattern": "/.json"} <|tool_call_end|> <|tool_call_begin|> functions.glob:2 <|tool_call_argument_begin|> {"pattern": "*/.{js,ts,jsx,tsx}"} <|tool_call_end|> <|tool_call_begin|> functions.glob:3 <|tool_call_argument_begin|> {"pattern": "*/*.{py,java,go,rs,c,cpp}"} <|tool_call_end|> <|tool_calls_section_end| ### Screenshot and/or share link <img width="2798" height="340" alt="Image" src="https://github.com/user-attachments/assets/131ff642-093c-4d4f-bff1-8ce12f025c5d" /> ### Operating System NixOS unstable ### Terminal kitty
yindo added the bugnix labels 2026-02-16 18:04:16 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 16, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #8010: Expected thinking or redacted_thinking but found tool_use - Similar issue with Claude models where tool calls appear outside thinking blocks
  • #6708: GLM 4.7 on Zai coding plan puts tool calls inside the thinking/reasoning tag - Same core problem with tool call tokens appearing in thinking blocks
  • #5630: Amazon Bedrock Kimi2 Thinking output - Related issue with Kimi2 thinking model displaying tool call tokens in output
  • #1522: Qwen3 as well as Kimi K2 keep stopping mid-chat - Related issue with Kimi K2 via OpenRouter

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 16, 2026): This issue might be a duplicate of existing issues. Please check: - #8010: Expected `thinking` or `redacted_thinking` but found `tool_use` - Similar issue with Claude models where tool calls appear outside thinking blocks - #6708: GLM 4.7 on Zai coding plan puts tool calls inside the thinking/reasoning tag - Same core problem with tool call tokens appearing in thinking blocks - #5630: Amazon Bedrock Kimi2 Thinking output - Related issue with Kimi2 thinking model displaying tool call tokens in output - #1522: Qwen3 as well as Kimi K2 keep stopping mid-chat - Related issue with Kimi K2 via OpenRouter Feel free to ignore if none of these address your specific case.
Author
Owner

@juanfadev commented on GitHub (Jan 17, 2026):

Same with KimiK2 Thinking in nvidia provider:

Thinking: <|tool_calls_section_begin|> <|tool_call_begin|> functions.bash:1 <|tool_call_argument_begin|> {"command": "ls -la /home/user/repo", "description": "List directory"} <|tool_call_end|> <|tool_calls_section_end|>

@juanfadev commented on GitHub (Jan 17, 2026): Same with KimiK2 Thinking in nvidia provider: Thinking: <|tool_calls_section_begin|> <|tool_call_begin|> functions.bash:1 <|tool_call_argument_begin|> {"command": "ls -la /home/user/repo", "description": "List directory"} <|tool_call_end|> <|tool_calls_section_end|>
Author
Owner

@graham33 commented on GitHub (Jan 18, 2026):

Looking at this in a bit more detail, it looks like there is an open bug with the Kimi-K2 model itself: https://github.com/MoonshotAI/Kimi-K2/issues/89 and vLLM implements a workaround for it: https://github.com/vllm-project/vllm/pull/28543

This also seems similar to this issue with GLM 4.7: https://github.com/anomalyco/opencode/issues/6708, although there it seems more sporadic whereas with Kimi-K2 it happens a lot.

@graham33 commented on GitHub (Jan 18, 2026): Looking at this in a bit more detail, it looks like there is an open bug with the Kimi-K2 model itself: https://github.com/MoonshotAI/Kimi-K2/issues/89 and vLLM implements a workaround for it: https://github.com/vllm-project/vllm/pull/28543 This also seems similar to this issue with GLM 4.7: https://github.com/anomalyco/opencode/issues/6708, although there it seems more sporadic whereas with Kimi-K2 it happens a lot.
Author
Owner

@qingchunnh commented on GitHub (Jan 27, 2026):

I solved this issue following #6040. Hope this helps.

@qingchunnh commented on GitHub (Jan 27, 2026): I solved this issue following #6040. Hope this helps.
Author
Owner

@pascalandy commented on GitHub (Jan 28, 2026):

Provider returned error

Image

All other models from OpenRouter are stable on my setup.
v1.1.39

@pascalandy commented on GitHub (Jan 28, 2026): > Provider returned error ![Image](https://github.com/user-attachments/assets/52c03423-da0b-4335-925d-87754c07296f) All other models from OpenRouter are stable on my setup. v1.1.39
Author
Owner

@wwnbb commented on GitHub (Feb 12, 2026):

I solved this issue following #6040. Hope this helps.

can you describe how you manage to fix the problem?

@wwnbb commented on GitHub (Feb 12, 2026): > I solved this issue following [#6040](https://github.com/anomalyco/opencode/issues/6040). Hope this helps. can you describe how you manage to fix the problem?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#6453