Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion plugins/model-providers/kimi-coding/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
class KimiProfile(ProviderProfile):
"""Kimi/Moonshot — temperature omitted, thinking xor reasoning_effort."""

def _is_coding_endpoint(self, base_url: str | None) -> bool:
"""True for the Anthropic-shaped api.kimi.com/coding endpoint, which
only allows thinking {"type": "enabled"} (vs the OpenAI-compat /v1
endpoint, which accepts both enabled and disabled)."""
eff = (base_url or self.base_url or "")
return "/coding" in eff

def build_api_kwargs_extras(
self, *, reasoning_config: dict | None = None, **context
) -> tuple[dict[str, Any], dict[str, Any]]:
Expand All @@ -40,7 +47,16 @@ def build_api_kwargs_extras(

enabled = reasoning_config.get("enabled", True)
if enabled is False:
extra_body["thinking"] = {"type": "disabled"}
# The api.kimi.com/coding endpoint (Anthropic Messages-shaped) only
# accepts thinking {"type": "enabled"} and 400s on {"type":
# "disabled"} ("invalid thinking: only type=enabled is allowed for
# this model"). Thinking can't be turned off there, so emit the legal
# enabled toggle rather than a request the server rejects. The
# OpenAI-compat /v1 endpoint still honours disabled.
if self._is_coding_endpoint(context.get("base_url")):
extra_body["thinking"] = {"type": "enabled"}
else:
extra_body["thinking"] = {"type": "disabled"}
return extra_body, top_level

# Enabled: prefer an explicit effort; only fall back to extra_body
Expand Down
11 changes: 11 additions & 0 deletions tests/plugins/model_providers/test_kimi_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ def test_disabled_ignores_effort(self, kimi_profile):
assert extra_body == {"thinking": {"type": "disabled"}}
assert top_level == {}

def test_coding_endpoint_never_disables_thinking(self, kimi_profile):
"""api.kimi.com/coding (Anthropic-shaped) 400s on thinking
{"type": "disabled"} ("only type=enabled is allowed for this model"),
so a disable request must degrade to the legal enabled toggle there."""
for rc in ({"enabled": False}, {"enabled": False, "effort": "high"}):
extra_body, top_level = kimi_profile.build_api_kwargs_extras(
reasoning_config=rc, base_url="https://api.kimi.com/coding"
)
assert extra_body == {"thinking": {"type": "enabled"}}
assert top_level == {}

@pytest.mark.parametrize(
"reasoning_config",
[
Expand Down