-
[NA] [BE] fix: register moonshot as a canonical provider so Moonshot model prices load (#7604)
发布于
2026-07-27 11:02:04 +00:00 - [NA] [BE] fix: register moonshot as a canonical provider so Moonshot model prices load
Following the pattern of the recent provider-registration fixes for azure
(#7262), xai (#7433), deepseek (#7434), perplexity (#7432) and fireworks_ai
(#7554), Moonshot AI's 22 non-zero-cost entries in
model_prices_and_context_window.json (the moonshot-v1-* legacy models and the
kimi-* family) currently drop at load time because moonshot is not in
PROVIDERS_MAPPING, so buildModelPrice returns null for every one of them and
Moonshot spans never get a cost.Add moonshot -> moonshot to PROVIDERS_MAPPING, and route it through
textGenerationWithCacheCostOpenAI in PROVIDERS_CACHE_COST_CALCULATOR. Moonshot's
API is OpenAI-compatible and its LiteLLM cost calculator delegates to
generic_cost_per_token, so cached tokens are flattened under
prompt_tokens_details.cached_tokens, matching the OpenAI/Azure/xAI/DeepSeek/
Fireworks routing. Twelve of the 22 Moonshot models publish
cache_read_input_token_cost (all kimi-k2 variants), so this fix meaningfully
discounts the cache-hit path for the kimi family instead of overcharging every
cached prompt token at the full input rate.Parameterized test covers both branches: moonshot-v1-8k (no cache rates ->
textGenerationCost) and kimi-k2-0711-preview (cache rates -> cache-aware OpenAI
route).- address Baz: alias moonshotai -> moonshot for OpenRouter-namespaced Kimi models
OpenRouter enumerates Moonshot's Kimi family under a distinct namespace prefix
(moonshotai/) than LiteLLM's canonical (moonshot/); see the MOONSHOTAI_KIMI_*
entries in OpenRouterModelName. Without an alias in PROVIDERS_MAPPING, the
provider-prefix fallback in findModelPrice returns null for those callers and
they silently resolve to DEFAULT_COST — under-charging every Kimi call routed
through OpenRouter / any aggregator.Add moonshotai -> moonshot alongside the existing moonshot -> moonshot canonical
entry, mirroring the microsoft -> azure override pattern already in the map. No
JSON entries carry litellm_provider="moonshotai" today, so this is pure aggregator
routing help; it changes no existing lookup semantics.Parameterized regression test exercises the aggregator path with provider="openrouter"
and provider="custom-llm" on both a cache-priced (kimi-k2-0711-preview) and
non-cache (moonshot-v1-8k) model.
Co-authored-by: Andres Cruz andresc@comet.com
下载附件