wu-sheng opened a new pull request, #13758:
URL: https://github.com/apache/skywalking/pull/13758

   ### Support model prefix matching and aliases for GenAI pricing config
   - [x] If this is non-trivial feature, paste the links/URLs to the design doc.
     - Related to SWIP-10: 
https://github.com/apache/skywalking/discussions/13756
   - [x] Update the documentation to include this new feature.
   - [x] Tests(including UT, IT, E2E) are added to verify the new feature.
   
   **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:
      ```yaml
      - name: claude-4-sonnet
        aliases: [claude-sonnet-4]
      ```
   
   3. **Move shared utils to library-util** — `GenAIPricingConfig`, 
`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 #<issue number>.
   - [ ] Update the [`CHANGES` 
log](https://github.com/apache/skywalking/blob/master/docs/en/changes/changes.md).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to