Skip to content

Support model prefix matching and aliases for GenAI pricing#13758

Merged
wu-sheng merged 3 commits intomasterfrom
feature/genai-model-prefix-match-aliases
Mar 26, 2026
Merged

Support model prefix matching and aliases for GenAI pricing#13758
wu-sheng merged 3 commits intomasterfrom
feature/genai-model-prefix-match-aliases

Conversation

@wu-sheng
Copy link
Copy Markdown
Member

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 in gen-ai-config.yml (e.g., gpt-4o, claude-4-sonnet). This causes cost estimation to fail silently.

Changes:

  1. Trie-based longest-prefix model matching — replaces exact HashMap.get() lookup. Now gpt-4o-2024-08-06 matches config entry gpt-4o, and gpt-4o-mini-2024-07-18 correctly matches gpt-4o-mini (longer prefix wins).

  2. Model aliases — Anthropic uses reversed naming (claude-sonnet-4) vs config (claude-4-sonnet). Aliases allow one pricing entry to match both conventions:

    - name: claude-4-sonnet
      aliases: [claude-sonnet-4]
  3. Move shared utils to library-utilGenAIPricingConfig, GenAIPricingConfigLoader, GenAIModelMatcher moved to server-library/library-util genai package for shared access by both agent-based analysis (gen-ai-analyzer) and future OTLP-based monitoring (meter-analyzer MAL scripts).

  4. Anthropic aliases added to gen-ai-config.yml for all Claude models (API response naming: claude-{tier}-{version} format).

  • If this pull request closes/resolves/fixes an existing issue, replace the issue number. Closes #.
  • Update the CHANGES log.

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
@wu-sheng wu-sheng requested a review from wankai123 March 26, 2026 02:03
@wu-sheng wu-sheng added the enhancement Enhancement on performance or codes label Mar 26, 2026
@wu-sheng wu-sheng added this to the 10.4.0 milestone Mar 26, 2026
@wu-sheng
Copy link
Copy Markdown
Member Author

@peachisai, I refactored the cost estimation tool into util, as I am going to add ai gw support.

@wu-sheng wu-sheng merged commit ce2ba33 into master Mar 26, 2026
373 of 376 checks passed
@wu-sheng wu-sheng deleted the feature/genai-model-prefix-match-aliases branch March 26, 2026 03:10
@peachisai
Copy link
Copy Markdown
Member

@peachisai, I refactored the cost estimation tool into util, as I am going to add ai gw support.

Noted. I will proceed with the OTLP trace analysis and documentation writing based on the new logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Enhancement on performance or codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants