Fixing error 400 on Kimi K2.5 in thinking mode#5544
Fixing error 400 on Kimi K2.5 in thinking mode#5544Neonsy wants to merge 24 commits intoKilo-Org:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 4bf6ca0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Fixing an error related to Kimi K2.5's behavior.
|
I'm on it to improve type-safety |
|
I'm running tests and verify the type-safety changes |
|
I'm done on my end with 52ad122 Besides on chore nitpick, but that will hopefully be the last thing 😁 cause I overlooked something |
|
This is the final commit from my end now (I hope) 😄 |
|
@kevinvandijk Do you know when the person you have requested as a reviewer will be available, or if there is someone else. I don't wanna rush things, but this PR is blocking everyone from using the Moonshot provider with thinking enabled (At least K2.5, if not others) |
The official merger cycle seems to average a month... |
|
@CaiDingxian Maybe That's how your PR got merged with the endpoint, because I discovered it and asked about it. |
|
My first usage of latest main with this fix are positive. It seems LLM got smarter with this thinking mode enabled properly. I will continue to use it and update here only if I find any issue. |
Tried following commandpnpm install:vsixefe9cef fixed the jetbrains part, that was sadly not windows compatible 😭 |
Looks like main broke my stuff042d403 should fix that (hopefully) |
|
Why did those runs cancel ❓ |
What happened on 0fd94d9pnpm install ran postinstall for @vscode/ripgrep
It got HTTP 403 on every attempt, so the postinstall failed and the whole install exited. |
Maybe you are right. I lost all hope. |
|
Hi @Neonsy, We were not convinced this would not break other providers which is why we were checking for other solutions but should have commented that here, I'm not sure why that didn't happen. Apologies for that! Because we also rely on upstream and there the moonshot provider was converted to use the Vercel AI SDK we pulled in #5662. This should actually also fix the reasoning on Kimi 2.5. I have not seen any 400s anymore since this, can you let me know if that fixed it for you too? If not I'll reconsider this PR with priority. Feel free to DM me about it on Discord in that case as well! |
hello @kevinvandijk . I have been heavy using Neonsy VSIX with his fix for past couple of days with Kimi Coding Plan as a solution. Since you released 5.3.3 4 hours ago -> i have switched to it NOW , and i will spent next 3-4 hours using it I will let you know at the end of my working day (2-3 more hours) if i have stubled upon any issues. |
|
@kevinvandijk If it works, then I understand that it is safer to use what comes from upstream. I'm currently no longer using the Kilo extension, but @smetanokr as already replied. I accept whichever decision is considered best for the codebase. |
|
Let's see if updating this branch will break my fix due to upstream stuff |
@kevinvandijk could you please elaborate as to why this conclusion has been drawn. Did any testing reveal that? Does the code look like it would break with other providers? I would like to understand if there is evidence. |
|
@kevinvandijk i can share with you kimi code api key , if it will help you with investigation -> to find out why cherry-pick-kimi-sdk is not a sucess and kimi k2.5 is still unable to do tool calls |
|
@smetanokr Well looks like main broke my fix I can no longer see a thinking checkbox and Kimi is looping hard. Therefore I will no longer tend to this PR. |
|
Maybe this helps (hope you guys find a way, as I don't wanna spend more time trying to fix what main breaks... It's not fun): |
|
@Neonsy |
As said, the upstream bit wrecked my fix and I don't wanna have to spend time on something, that comes from somewhere else, as it has been a decision from the team. Therefore the chance of my fix being applied is slim. I don't wanna work on something, that is most likely not going to be merged. I've forced pushed backwards to remove what broke the fix, so my branch should still work. |
|
created new issue for it #5719 as this one seems to be closed |





Context
Fixes the "400 thinking is enabled but reasoning_content is missing in assistant tool call message" error when using Kimi K2.5 models (via Moonshot provider) with thinking enabled during multi-step tool calling.
Error Encountered:
According to the Moonshot documentation, when using Kimi K2.5 with thinking enabled:
reasoning_contentas a top-level field in assistant messagesreasoning_contentmust be preserved in the contextreasoning_contentis missing from assistant messages withtool_calls, the API returns a 400 errorThis fix ensures that reasoning blocks stored in the internal message format are properly extracted and added as
reasoning_contentat the message level when converting back to OpenAI format for API requests.Closes #3996
Implementation
The Problem
The message conversion flow was losing
reasoning_content:openai.tsreceivesreasoning_contentin the delta and yields it as areasoningchunkTask.tsstores reasoning as{type: "reasoning", text: "..."}blocks in the message content arrayconvertToOpenAiMessages()converts messages back to OpenAI format but did NOT extract reasoning blocks and map them toreasoning_contentreasoning_contentwas missing → 400 errorThe Fix
Modified
src/api/transform/openai-format.tsto:type: "reasoning"ortype: "thinking"from the message contentreasoning_content: Join multiple reasoning blocks with newlines and add as a top-level message field (not inside content array)reasoning_contentorreasoningalready present at the message level (for re-conversion scenarios)reasoning_detailshandling for Gemini 3 / xAI remains unchanged and works alongside the newreasoning_contentextractionKey Code Changes
Tradeoffs
reasoning_contentbeforereasoning_detailsandtool_callsto preserve the order expected by providers. Property order matters when sending messages back to some APIs.reasoning_detailshandling is preserved, andreasoning_contentis only added when reasoning blocks exist.Screenshots
thinking is enabled but reasoning_content is missing in assistant tool call message at index 2How to Test
Configure Kimi K2.5 model via Moonshot provider:
Start a task that requires multi-step tool calling:
read_filetool callVerify the conversation continues after the tool result:
Check that reasoning is preserved:
Test Coverage
Added comprehensive tests in
openai-format.spec.tscovering:reasoning_contentreasoning_contentpreservationreasoning_contentandreasoning_detailsAffected Providers and Models
Directly Affected (require
reasoning_contentat message level)kimi-k2.5,kimi-k2.5-thinkingreasoning_contenton all assistant messages with thinking enableddeepseek-reasoner,deepseek-r1reasoning_contentduring multi-step tool callingIndirectly Benefited (reasoning preserved correctly)
o1,o3,o4seriesgrok-3reasoning_detailsformat, but benefits from consistent handlinggemini-2.5-proreasoning_detailsformat, unchanged but compatibleNot Affected
thinkingblocks within content array