From e71af8db031e86236daa0caa7bf6e65975bb873a Mon Sep 17 00:00:00 2001 From: helenanova Date: Wed, 16 Sep 2026 02:05:52 -0700 Subject: [PATCH] fix(pricing): prefer the first-party route on equally priced model ties resolve_litellm_model() returned matches[0] (alphabetical) when several provider routes shared identical pricing, which resolves bare names like grok-4.5 to the openrouter aggregator alias instead of the first-party xai route. On a price tie, prefer the route whose model segment matches the bare name exactly, keeping alphabetical order as the fallback. Fixes #1288 --- strix/report/pricing.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/strix/report/pricing.py b/strix/report/pricing.py index 57c89959..4474f0fb 100644 --- a/strix/report/pricing.py +++ b/strix/report/pricing.py @@ -48,7 +48,10 @@ def resolve_litellm_model(model: str) -> str | None: if isinstance(model_cost.get(key), dict) } if len(matches) == 1 or len(prices) == 1: - return matches[0] + # On a price tie, prefer the route whose model segment is exactly the + # bare name (the first-party route) over aggregator aliases like + # openrouter/x-ai/; fall back to alphabetical order. + return min(matches, key=lambda key: (key.split("/", 1)[1] != name, key)) return None # noqa: TRY300 except Exception: # noqa: BLE001 return None