fix(pricingRegistry): normalize model names to lowercase for case-insensitive lookup#11
Open
Srejoye wants to merge 1 commit into
Open
fix(pricingRegistry): normalize model names to lowercase for case-insensitive lookup#11Srejoye wants to merge 1 commit into
Srejoye wants to merge 1 commit into
Conversation
…ensitive lookup
register() stored model names as-is while getPricing() and hasPricing() looked them up as-is. A user calling registerPricing('openai', 'GPT-4o', ...) would cause a lookup failure when the API returned model: 'gpt-4o', since Map lookups are case-sensitive. The error was silently caught upstream, returning \ cost and leaving the API call completely untracked.
Add model.toLowerCase() normalization in register(), getPricing(), and hasPricing(). All built-in model registrations already use lowercase so existing behavior is fully preserved. Error messages retain the original model string for clear user-facing diagnostics.
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.
Problem
register()stored model names exactly as passed, whilegetPricing()andhasPricing()looked them up exactly as passed. JavaScriptMapkeys are case-sensitive, soregisterPricing("openai", "GPT-4o", ...)followed by a lookup for"gpt-4o"(the format API responses use) silently failed.The error from
getPricing()was caught upstream in the cost engine, which returned$0— causing the API call to go completely untracked with no warning to the user.Root Cause
src/core/pricingRegistry.ts— three methods:register()line 120:set(model, pricing)— no normalizationgetPricing()line 134:providerPricing.get(model)— no normalizationhasPricing()line 147:.has(model)— no normalizationProvider names were normalized (
provider.toLowerCase()) but model names were not, creating an inconsistent API surface.Fix
Add
const normalizedModel = model.toLowerCase()in all three methods and use it for Map operations. Error messages retain the originalmodelstring for readable diagnostics.Compatibility
All built-in model registrations in
initializeDefaultPricing()already use lowercase strings — existing behavior is 100% preserved. This only affects users who calledregisterPricing()with mixed-case model names.Behaviour
register("openai", "GPT-4o")thengetPricing("openai", "gpt-4o")hasPricing("openai", "GPT-4O")falsetrue✓Closes #7