-
[BE] fix: register perplexity as a canonical provider so Perplexity model prices load (#7432)
发布于
2026-07-15 11:23:00 +00:00 - [BE] fix: register perplexity as a canonical provider so Perplexity model prices load
Following the pattern of #7262 (which registered
azure), Perplexity's 41
entries inmodel_prices_and_context_window.jsoncurrently drop at load
time becauseperplexityis not in PROVIDERS_MAPPING. Of those 41, 16
publish non-zero input+output rates — thesonarfamily (sonar, sonar-pro,
sonar-reasoning*, sonar-deep-research) plus the legacy
perplexity/llama-*andperplexity/codellama-*chat models. None
publish cache_read or cache_creation rates, so Perplexity requests route
cleanly through textGenerationCost and no cache-calculator wiring is
needed.Add
perplexity -> perplexityto PROVIDERS_MAPPING; no other changes.Parameterized integration test uses
perplexity/sonar(input=output=1e-6)
andperplexity/sonar-pro(input 3e-6 / output 1.5e-5), covering both a
uniform-rate model and a model where input and output rates differ, to
prove the plumbing routes correctly.- [BE] fix: fall back to model-name provider prefix when aggregator routing misses
Addressing baz-reviewer's High-severity finding on #7432. Registering
perplexityas a canonical provider (this PR's original scope) fixes
direct callers, but BudgetGuard also invokes CostService.calculateCost via
LlmProviderFactoryImpl.getResolvedModelInfo(), which enumerates
perplexity/*,xai/*, anddeepseek/*under OpenRouter and therefore
returnsprovider="openrouter". Without an openrouter row for these
models the lookup lands on DEFAULT_COST and Perplexity-hosted evaluations
charge $0.Add a final fallback in
findModelPrice: when every primary lookup has
missed and the original model name carries a provider prefix that maps to
a canonical provider we know pricing for (e.g.perplexity/sonarmaps
prefixperplexity-> canonicalperplexity), retry the lookup under
that prefix's canonical provider. Only kicks in as a fallback so no
existing lookup semantics change for callers that already pass a matching
provider directly, and only when the prefix appears in PROVIDERS_MAPPING
so unmapped prefixes cannot leak through.The same fallback covers the parallel deepseek and xai cases (#7434,
#7433) — those models are also enumerated under OpenRouter and would
otherwise silently drop to $0 through the aggregator-routed BudgetGuard
path.Parameterized test uses perplexity/sonar and perplexity/sonar-pro through
bothopenrouterandcustom-llmproviders; each returns the same cost
as the direct perplexity lookup.
Co-authored-by: Andres Cruz andresc@comet.com
下载附件