Skip to content

fix(pricingRegistry): normalize model names to lowercase for case-insensitive lookup#11

Open
Srejoye wants to merge 1 commit into
Ruthwik000:mainfrom
Srejoye:fix-pricingregistry-lowercase
Open

fix(pricingRegistry): normalize model names to lowercase for case-insensitive lookup#11
Srejoye wants to merge 1 commit into
Ruthwik000:mainfrom
Srejoye:fix-pricingregistry-lowercase

Conversation

@Srejoye
Copy link
Copy Markdown

@Srejoye Srejoye commented May 16, 2026

Problem

register() stored model names exactly as passed, while getPricing() and hasPricing() looked them up exactly as passed. JavaScript Map keys are case-sensitive, so registerPricing("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 normalization
  • getPricing() line 134: providerPricing.get(model) — no normalization
  • hasPricing() line 147: .has(model) — no normalization

Provider 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 original model string 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 called registerPricing() with mixed-case model names.

Behaviour

Scenario Before After
register("openai", "GPT-4o") then getPricing("openai", "gpt-4o") throws → silent $0 returns pricing ✓
hasPricing("openai", "GPT-4O") false true
All built-in model lookups work work ✓ (unchanged)
Provider name case-insensitivity works works ✓ (unchanged)

Closes #7

…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.
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.

fix(pricingRegistry): normalize model names to lowercase for case-insensitive lookup

1 participant