Resolve kimi-k3 context length to 1M on canonical Kimi Coding endpoints

Kimi Coding serves K3 under the bare slug 'k3', but users can also
configure or select the public-facing aliases 'kimi-k3' and
'kimi-k3-cot'. The endpoint-scoped 1M context window was only keyed
on the bare 'k3' slug, so selecting 'kimi-k3' fell through to the
generic 'kimi' catch-all (262k).

Extend the guard in _endpoint_scoped_context_length to also recognize
'kimi-k3' and 'kimi-k3-cot', while keeping the endpoint check that
limits the 1M value to https://api.kimi.com/coding (legacy Moonshot
endpoints still fall back to 262k). Update the existing test to cover
all three aliases.

Fixes: context window limited to 262k when using kimi-k3 via kimi-coding.
This commit is contained in:
githubespresso407 2026-07-18 15:09:43 -05:00 committed by Teknium
parent c363db81e0
commit 77aa026ca6
2 changed files with 16 additions and 8 deletions

View file

@ -543,7 +543,13 @@ def _is_known_provider_base_url(base_url: str) -> bool:
def _endpoint_scoped_context_length(model: str, base_url: str) -> Optional[int]:
"""Return metadata confirmed only for one provider endpoint."""
"""Return metadata confirmed only for the Kimi Coding endpoint.
Kimi Coding serves K3 under the bare slug ``k3``, but users may also
configure or select the public-facing aliases ``kimi-k3`` and
``kimi-k3-cot``. Only canonical ``https://api.kimi.com/coding`` endpoints
(legacy Moonshot keys do not serve K3) get the 1 Mi context window.
"""
normalized = _normalize_base_url(base_url)
try:
parsed = urlparse(normalized)
@ -559,7 +565,7 @@ def _endpoint_scoped_context_length(model: str, base_url: str) -> Optional[int]:
and parsed.path.rstrip("/") in {"/coding", "/coding/v1"}
and not parsed.query
and not parsed.fragment
and model.strip().lower() == "k3"
and model.strip().lower() in {"k3", "kimi-k3", "kimi-k3-cot"}
):
return 1_048_576
return None

View file

@ -199,14 +199,16 @@ class TestDefaultContextLengths:
)
for base_url in accepted_urls:
assert get_model_context_length(
"k3", provider="kimi-coding", base_url=base_url
) == 1_048_576
for model in ("k3", "kimi-k3", "kimi-k3-cot"):
assert get_model_context_length(
model, provider="kimi-coding", base_url=base_url
) == 1_048_576
for base_url in rejected_urls:
assert get_model_context_length(
"k3", provider="kimi-coding", base_url=base_url
) != 1_048_576
for model in ("k3", "kimi-k3", "kimi-k3-cot"):
assert get_model_context_length(
model, provider="kimi-coding", base_url=base_url
) != 1_048_576
def test_grok_substring_matching(self):
# Longest-first substring matching must resolve the real xAI model