fix(model-metadata): skip OpenRouter for known providers, add kimi/moonshot to PROVIDER_TO_MODELS_DEV

Based on PR #23950 by @nicoechaniz.

- Add "kimi" and "moonshot" to PROVIDER_TO_MODELS_DEV → kimi-for-coding
- Gate OpenRouter metadata step behind "if not effective_provider":
  known providers should not be overridden by community-maintained OR data
- Keep the targeted Kimi-family 32k guard as a secondary safety net
  inside the OR gate (for unknown providers with Kimi models)

Co-authored-by: nicoechaniz <nicoechaniz@altermundi.net>
This commit is contained in:
nicoechaniz 2026-05-12 01:38:43 +05:30 committed by kshitij
parent 91eef6255e
commit e2b713cced
2 changed files with 29 additions and 21 deletions

View file

@ -1566,27 +1566,33 @@ def get_model_context_length(
if ctx: if ctx:
return ctx return ctx
# 6. OpenRouter live API metadata (provider-unaware fallback) # 6. OpenRouter live API metadata — provider-unaware fallback.
metadata = fetch_model_metadata() # Only consulted when the provider is unknown (no effective_provider),
if model in metadata: # because OpenRouter data is community-maintained and can be incorrect
or_ctx = metadata[model].get("context_length", DEFAULT_FALLBACK_CONTEXT) # for models that belong to known providers with curated defaults.
# Guard against stale OpenRouter metadata for Kimi-family models. if not effective_provider:
# OpenRouter reports 32768 for moonshotai/kimi-k2.6, but the model metadata = fetch_model_metadata()
# actually supports 262144 (models.dev + official Kimi docs agree). if model in metadata:
# Providers that host their own Kimi endpoints (Ollama Cloud, Kimi or_ctx = metadata[model].get("context_length", DEFAULT_FALLBACK_CONTEXT)
# Coding, Moonshot) would otherwise trip the 64k minimum-context # Guard against stale OpenRouter metadata for Kimi-family models.
# guard and reject a perfectly capable model. # OpenRouter reports 32768 for moonshotai/kimi-k2.6, but the model
# The filter is narrow: only reject exactly 32768 for Kimi-named # actually supports 262144 (models.dev + official Kimi docs agree).
# models. If OpenRouter ever updates its data, the stale path # Providers that host their own Kimi endpoints (Ollama Cloud, Kimi
# becomes dead code with no impact. # Coding, Moonshot) would otherwise trip the 64k minimum-context
if or_ctx == 32768 and _model_name_suggests_kimi(model): # guard and reject a perfectly capable model.
logger.info( # The filter is narrow: only reject exactly 32768 for Kimi-named
"Rejecting OpenRouter metadata context=%s for %r " # models. If OpenRouter ever updates its data, the stale path
"(Kimi-family underreport); falling through to hardcoded defaults", # becomes dead code with no impact.
or_ctx, model, if or_ctx == 32768 and _model_name_suggests_kimi(model):
) logger.info(
else: "Rejecting OpenRouter metadata context=%s for %r "
return or_ctx "(Kimi-family underreport); falling through to hardcoded defaults",
or_ctx, model,
)
else:
return or_ctx
# 7. (reserved)
# 8. Hardcoded defaults (fuzzy match — longest key first for specificity) # 8. Hardcoded defaults (fuzzy match — longest key first for specificity)
# Only check `default_model in model` (is the key a substring of the input). # Only check `default_model in model` (is the key a substring of the input).

View file

@ -145,7 +145,9 @@ PROVIDER_TO_MODELS_DEV: Dict[str, str] = {
"openai": "openai", "openai": "openai",
"openai-codex": "openai", "openai-codex": "openai",
"zai": "zai", "zai": "zai",
"kimi": "kimi-for-coding",
"kimi-coding": "kimi-for-coding", "kimi-coding": "kimi-for-coding",
"moonshot": "kimi-for-coding",
"stepfun": "stepfun", "stepfun": "stepfun",
"kimi-coding-cn": "kimi-for-coding", "kimi-coding-cn": "kimi-for-coding",
"minimax": "minimax", "minimax": "minimax",