Support model prefix matching and aliases for GenAI pricing#13758
Merged
Support model prefix matching and aliases for GenAI pricing#13758
Conversation
Move GenAI model matcher and config loader to library-util for shared access by both agent-based analysis and future MAL-based OTLP processing. - Add GenAIModelMatcher with Trie-based longest-prefix match for both provider identification and model cost lookup (was exact match only) - Add model aliases support so one pricing entry matches multiple naming conventions (e.g., claude-4-sonnet and claude-sonnet-4) - Add GenAIPricingConfig and GenAIPricingConfigLoader in library-util - Add Anthropic API response name aliases to gen-ai-config.yml - gen-ai-analyzer delegates to shared library-util classes
Member
Author
|
@peachisai, I refactored the cost estimation tool into util, as I am going to add ai gw support. |
wankai123
approved these changes
Mar 26, 2026
Member
Noted. I will proceed with the OTLP trace analysis and documentation writing based on the new logic. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Support model prefix matching and aliases for GenAI pricing config
Problem: LLM providers return versioned model names in API responses (e.g.,
gpt-4o-2024-08-06,claude-sonnet-4-20250514), which don't match the exact model names ingen-ai-config.yml(e.g.,gpt-4o,claude-4-sonnet). This causes cost estimation to fail silently.Changes:
Trie-based longest-prefix model matching — replaces exact
HashMap.get()lookup. Nowgpt-4o-2024-08-06matches config entrygpt-4o, andgpt-4o-mini-2024-07-18correctly matchesgpt-4o-mini(longer prefix wins).Model aliases — Anthropic uses reversed naming (
claude-sonnet-4) vs config (claude-4-sonnet). Aliases allow one pricing entry to match both conventions:Move shared utils to library-util —
GenAIPricingConfig,GenAIPricingConfigLoader,GenAIModelMatchermoved toserver-library/library-utilgenai package for shared access by both agent-based analysis (gen-ai-analyzer) and future OTLP-based monitoring (meter-analyzer MAL scripts).Anthropic aliases added to
gen-ai-config.ymlfor all Claude models (API response naming:claude-{tier}-{version}format).CHANGESlog.