jcode icon indicating copy to clipboard operation
jcode copied to clipboard

Kimi API fails with tool calls when thinking mode is enabled

Open kskim opened this issue 6 months ago • 1 comments

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

  1. Send a chat completion request to the Kimi OpenAI-compatible endpoint.
  2. Use the kimi-for-coding model.
  3. Enable thinking/reasoning mode.
  4. Allow the model to generate one or more tool calls.
  5. 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.

kskim avatar Jun 04 '26 07:06 kskim

Reproduced and fixed in f8d25110.

Root cause: the dedicated Kimi coding endpoint (https://api.kimi.com/coding/v1, default model kimi-for-coding) enables thinking server-side and requires reasoning_content on assistant tool-call messages. But jcode's request builder gated reasoning_content behind two conditions that both failed for this endpoint:

  1. is_kimi_model("kimi-for-coding") returns false (it only matches moonshotai/ and kimi-k2* variants).
  2. The Kimi profile runs as a direct OpenAI-compatible provider (supports_provider_features = false), so allow_reasoning/include_reasoning_content stayed false.

As a result the assistant tool-call message was serialized as e.g. {"role":"assistant","tool_calls":[...]} with no reasoning_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 attach reasoning_content to assistant tool-call messages (a single space placeholder when no reasoning was persisted). Importantly the fix does NOT add the OpenRouter-specific top-level thinking field, 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-empty reasoning_content.

Will close automatically on the next release.

1jehuang avatar Jun 05 '26 07:06 1jehuang