-
[BE] fix: register xai as a canonical provider so xAI/Grok model prices load (#7433)
发布于
2026-07-13 09:39:34 +00:00 Following the pattern of #7262 (azure) and #7432 (perplexity) —
xaiis
not currently in PROVIDERS_MAPPING, so all 40 entries in
model_prices_and_context_window.json tagged with litellm_provider: "xai"
silently drop at load time. Every one publishes non-zero input+output
rates: the grok-2 / grok-3 / grok-4 / grok-4-fast / grok-code families.29 of the 40 also publish cache_read_input_token_cost. xAI's cost calc in
LiteLLM (litellm/llms/xai/cost_calculator.py) delegates to
generic_cost_per_token, which is the same helper OpenAI uses — so xai's
usage payload follows OpenAI's shape (prompt_tokens_details.cached_tokens
flattened into original_usage.*). That means xai routes cleanly through
the existing textGenerationWithCacheCostOpenAI calculator: no new cache
calc needed, just a PROVIDERS_CACHE_COST_CALCULATOR entry mirroring the
azure one.Parameterized test uses xai/grok-2 (no cache rates -> textGenerationCost)
and xai/grok-3 (input 3e-6, output 1.5e-5, cache_read 7.5e-7 ->
textGenerationWithCacheCostOpenAI). Both branches exercised in
regressions.Co-authored-by: Andres Cruz andresc@comet.com
下载附件