fix(pricing): prefer the direct provider when resellers list the same price

LiteLLM's cost map now lists grok-4.5 under xai/, perplexity/xai/ and
openrouter/x-ai/ at identical prices, so alphabetical order resolved the
bare name to openrouter and failed test_resolves_common_bare_model_names.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
itzzdev09 2026-09-14 12:17:13 +05:30
parent f1fe458216
commit 76267dc97e

View file

@ -36,7 +36,12 @@ def resolve_litellm_model(model: str) -> str | None:
if "/" in normalized:
names.append(normalized.rsplit("/", 1)[-1])
for name in names:
matches = sorted(key for key in model_cost if key.endswith(f"/{name}"))
# Prefer the direct provider (``xai/grok-4.5``) over resellers
# listing the same model (``openrouter/x-ai/grok-4.5``).
matches = sorted(
(key for key in model_cost if key.endswith(f"/{name}")),
key=lambda key: (key.count("/"), key),
)
if not matches:
continue
prices = {