Skip to content

fix: strip provider prefixes from catalog keys and handle collisions - #3

Merged
vsraccubits merged 1 commit into
mainfrom
fix/litellm-provider-prefix
Feb 24, 2026
Merged

vsraccubits merged 1 commit into
mainfrom
fix/litellm-provider-prefix

Conversation

@vsraccubits

@vsraccubits vsraccubits commented Feb 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Strip redundant provider prefixes from catalog keys — LiteLLM entries like gemini/gemini-2.0-flash and deepseek/deepseek-chat had doubled prefixes in the catalog (e.g. gemini/gemini/gemini-2.0-flash). Added bedrock/, deepseek/, and sagemaker/ to STRIP_PREFIXES and introduced strip_provider_prefix() to produce clean {provider}/{model} keys.
  • Handle key collisions deterministically — LiteLLM sometimes ships both a bare key (deepseek-chat) and a prefixed key (deepseek/deepseek-chat) for the same model. After prefix stripping, both map to deepseek/deepseek-chat. The collision handler now always prefers the prefixed (canonical) entry regardless of iteration order.
  • Add collision handling tests — Two new tests verify the prefixed entry wins in both iteration orders. Existing tests updated to expect the new clean key format.

Changes

File What changed
src/bud_model_catalog/mappings.py Added bedrock/, deepseek/, sagemaker/ to STRIP_PREFIXES; added strip_provider_prefix() helper
src/bud_model_catalog/sources/litellm.py Use strip_provider_prefix() for key construction; added collision resolution logic
tests/test_litellm_source.py Updated key assertions to clean format; added 2 collision handling tests
tests/test_merger.py Updated gemini/gemini/gemini-2.0-flash to gemini/gemini-2.0-flash in fixture

Test plan

  • Existing tests updated to expect new key format
  • test_collision_prefers_prefixed_entry — bare key first, prefixed key second
  • test_collision_prefers_prefixed_entry_reverse_order — prefixed key first, bare key second
  • Run pytest -v to verify all tests pass
  • Run example script and verify catalog keys no longer have doubled prefixes

🤖 Generated with Claude Code

Strip LiteLLM provider prefixes (bedrock/, deepseek/, sagemaker/) from
catalog keys to produce cleaner URIs. When two LiteLLM entries collide
on the same key, prefer the prefixed (canonical) entry. Updates tests
to reflect the new key format.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @vsraccubits, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors how LiteLLM model catalog keys are generated and managed. It introduces a standardized approach to strip provider-specific prefixes from model keys, resulting in cleaner and more consistent URIs. Additionally, it implements a robust collision resolution strategy to ensure that when multiple LiteLLM entries map to the same catalog key, the most appropriate (prefixed) entry is retained, improving data integrity and catalog usability.

Highlights

  • Prefix Stripping: Implemented logic to remove LiteLLM provider prefixes (e.g., bedrock/, deepseek/, sagemaker/) from catalog keys to create cleaner URIs.
  • Collision Resolution: Added a mechanism to handle cases where different LiteLLM entries result in the same catalog key, prioritizing the canonical (prefixed) entry.
  • Test Updates: Updated existing tests and introduced new ones to validate the prefix stripping and collision handling logic.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/bud_model_catalog/mappings.py
    • Expanded the STRIP_PREFIXES dictionary to include bedrock, deepseek, and sagemaker providers.
    • Introduced a new utility function strip_provider_prefix to remove specified prefixes from model keys.
  • src/bud_model_catalog/sources/litellm.py
    • Imported STRIP_PREFIXES and strip_provider_prefix from mappings.py.
    • Modified the fetch method to use strip_provider_prefix when constructing new_key.
    • Added logic to detect and resolve catalog key collisions, preferring entries that originally included the provider prefix.
  • tests/test_litellm_source.py
    • Adjusted assertions in test_fetches_and_transforms_correctly and test_vertex_ai_gemini_only_filter to reflect the new, stripped key format.
    • Added two new asynchronous tests, test_collision_prefers_prefixed_entry and test_collision_prefers_prefixed_entry_reverse_order, to verify the collision handling mechanism.
  • tests/test_merger.py
    • Updated the litellm_models fixture to reflect the new, stripped key format for a Gemini model.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request successfully implements stripping of LiteLLM provider prefixes from catalog keys and adds logic to handle collisions by preferring canonical (prefixed) entries. The changes are well-tested and improve the clarity of the generated URIs. I have suggested an enhancement to the collision logging for better observability.

Comment on lines +179 to +187
if new_key in result:
prefix = STRIP_PREFIXES.get(tz_provider)
if prefix:
existing_original = result[new_key]["metadata"]["original_key"]
# Keep the prefixed entry (canonical LiteLLM routing format)
if existing_original.startswith(prefix) and not original_key.startswith(prefix):
skipped += 1
continue
logger.warning("Catalog key collision on '%s', overwriting", new_key)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The collision warning log could be more informative by including the specific original keys that are colliding. This helps in identifying which entries in the LiteLLM pricing data are causing the issue. Moving the extraction of existing_original outside the if prefix block allows it to be used in the log message regardless of whether a prefix is defined for the provider.

Suggested change
if new_key in result:
prefix = STRIP_PREFIXES.get(tz_provider)
if prefix:
existing_original = result[new_key]["metadata"]["original_key"]
# Keep the prefixed entry (canonical LiteLLM routing format)
if existing_original.startswith(prefix) and not original_key.startswith(prefix):
skipped += 1
continue
logger.warning("Catalog key collision on '%s', overwriting", new_key)
if new_key in result:
existing_original = result[new_key]["metadata"]["original_key"]
prefix = STRIP_PREFIXES.get(tz_provider)
if prefix:
# Keep the prefixed entry (canonical LiteLLM routing format)
if existing_original.startswith(prefix) and not original_key.startswith(prefix):
skipped += 1
continue
logger.warning(
"Catalog key collision on '%s': overwriting '%s' with '%s'",
new_key,
existing_original,
original_key,
)

@vsraccubits
vsraccubits merged commit da7849f into main Feb 24, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant