🤖 refactor: deduplicate OpenAI service_tier constants #1120
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.
Summary
Consolidate duplicated OpenAI service_tier enum definitions into a single source of truth, and implement service tier-aware cost calculations.
Changes
OPENAI_SERVICE_TIERSconstant array andOpenAIServiceTiertype inproviders.tsisValidServiceTier()type guard for runtime validationOPENAI_DEFAULT_SERVICE_TIERconstant ("auto")displayUsage.tsCost Calculation Implementation
Service tiers have different pricing from OpenAI:
input_cost_per_token_flex,output_cost_per_token_flex)input_cost_per_token_priority,output_cost_per_token_priority)The actual service tier is read from the response
providerMetadata.openai.serviceTier(not the requested tier), ensuring accurate cost display even when priority requests are downgraded to standard.Files Changed
src/common/constants/providers.ts- new constants and type guardsrc/common/orpc/schemas/api.ts- use shared constantsrc/common/orpc/schemas/providerOptions.ts- use shared constantsrc/node/services/aiService.ts- use type guardsrc/node/services/providerService.ts- use type guardsrc/browser/components/Settings/sections/ProvidersSection.tsx- use constantssrc/common/utils/tokens/displayUsage.ts- implement tier-based pricingsrc/common/utils/tokens/displayUsage.test.ts- add service tier cost testssrc/common/utils/tokens/modelStats.ts- add tier-specific cost fieldssrc/common/utils/ai/providerOptions.ts- use default constantGenerated with
mux