Repository navigation
Description
Bug: Kimi API fails with tool calls when thinking mode is enabled
Summary
Requests to the Kimi OpenAI-compatible API fail with a 400 Bad Request when using kimi-for-coding and tool calls while thinking mode is enabled.
Environment
- Endpoint: https://api.kimi.com/coding/v1/chat/completions
- Model: kimi-for-coding
- Authentication: KIMI_API_KEY
Error
json { "error": { "message": "thinking is enabled but reasoning_content is missing in assistant tool call message at index 134", "type": "invalid_request_error" } }
Steps to Reproduce
- Send a chat completion request to the Kimi OpenAI-compatible endpoint.
- Use the kimi-for-coding model.
- Enable thinking/reasoning mode.
- Allow the model to generate one or more tool calls.
- The request fails with HTTP 400.
Expected Behavior
The request should either:
- succeed when assistant tool call messages do not contain reasoning_content, or
- the API documentation should clearly specify that reasoning_content is required for assistant tool call messages when thinking mode is enabled.
Actual Behavior
The API returns:
text 400 Bad Request thinking is enabled but reasoning_content is missing in assistant tool call message at index 134
Additional Notes
The request is sent through the OpenAI-compatible API interface. The error suggests that the server expects a reasoning_content field in assistant tool call messages when thinking mode is enabled, but this requirement is not handled by OpenAI-compatible clients.
It would be helpful to clarify:
- Whether reasoning_content is mandatory for tool call messages.
- How OpenAI-compatible clients should populate this field.
- Whether compatibility mode should automatically handle missing reasoning_content.
Activity
1jehuang commentedon Jun 5, 2026
Reproduced and fixed in
f8d25110.Root cause: the dedicated Kimi coding endpoint (
https://api.kimi.com/coding/v1, default modelkimi-for-coding) enables thinking server-side and requiresreasoning_contenton assistant tool-call messages. But jcode's request builder gatedreasoning_contentbehind two conditions that both failed for this endpoint:is_kimi_model("kimi-for-coding")returns false (it only matchesmoonshotai/andkimi-k2*variants).supports_provider_features = false), soallow_reasoning/include_reasoning_contentstayed false.As a result the assistant tool-call message was serialized as e.g.
{"role":"assistant","tool_calls":[...]}with noreasoning_content, and the endpoint rejected the whole request with the 400 you saw.Fix: detect the dedicated Kimi coding endpoint (by profile id / api base /
kimi*model name) and attachreasoning_contentto assistant tool-call messages (a single space placeholder when no reasoning was persisted). Importantly the fix does NOT add the OpenRouter-specific top-levelthinkingfield, since this endpoint manages thinking itself. Added a regression test that captures the outgoing request body and asserts the tool-call message carries a non-emptyreasoning_content.Will close automatically on the next release.
fix(kimi): attach reasoning_content on tool-call messages for Kimi co…
fix(kimi): attach reasoning_content on tool-call messages for Kimi co…
fix(kimi): attach reasoning_content on tool-call messages for Kimi co…
fix(openrouter): only prefix-strip reasoning for Kimi's cumulative sn…
fix(provider): gate blank reasoning_content fill on the require contract