fix(usage): persist cost multiplier at provider level instead of also at the logger level#1433
Merged
waleedlatif1 merged 3 commits intostagingfrom Sep 24, 2025
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Greptile Overview
Summary
This PR fixes a bug where cost multipliers were being applied both at the provider level AND at the logger level, causing double application of the multiplier. The fix moves cost multiplication responsibility entirely to the provider level.
Key Changes:
- Provider layer: Now retrieves
getCostMultiplier()and applies it when calculating costs for billable model usage - Execution logger: Removed cost multiplier logic and now uses
totalCostdirectly from the cost summary - Cost calculation: Updated to accept separate input/output multipliers as parameters
- Consistency: Minor logger name standardization
Impact:
- Eliminates double application of cost multipliers
- Ensures consistent cost calculation across the system
- Maintains backward compatibility while fixing the billing bug
Confidence Score: 5/5
- This PR is safe to merge with minimal risk
- Score reflects a straightforward bug fix with clear intent. Changes are well-contained, address a specific issue (double application of cost multipliers), and maintain backward compatibility. The refactoring moves cost calculation responsibility to the appropriate layer without introducing new complexity.
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| apps/sim/providers/index.ts | 5/5 | Added cost multiplier retrieval and application at provider level for billable model usage |
| apps/sim/providers/utils.ts | 5/5 | Updated calculateCost function signature to accept input and output multipliers, removed redundant comments |
| apps/sim/lib/logs/execution/logger.ts | 5/5 | Removed cost multiplier logic and getCostMultiplier import, now uses totalCost directly from cost summary |
| apps/sim/app/api/billing/update-cost/route.ts | 5/5 | Minor logger name change from 'billing-update-cost' to 'BillingUpdateCostAPI' for consistency |
Sequence Diagram
sequenceDiagram
participant Client as Client Request
participant Provider as Provider Layer
participant Utils as Provider Utils
participant Env as Environment
participant Logger as Execution Logger
participant DB as Database
Client->>Provider: executeProviderRequest()
Provider->>Env: getCostMultiplier()
Env-->>Provider: costMultiplier
Provider->>Utils: calculateCost(model, tokens, multipliers)
Utils-->>Provider: cost with multipliers applied
Provider-->>Client: response with calculated cost
Note over Provider, Utils: NEW: Cost multiplier applied at provider level
Client->>Logger: completeWorkflowExecution(costSummary)
Note over Logger: REMOVED: No longer applies multiplier
Logger->>DB: Store totalCost directly
Logger->>DB: Update user stats with totalCost
Note over Logger, DB: Cost multiplier already applied, no duplication
3 files reviewed, no comments
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.
Summary
persist cost with multiplier at provider level instead of conditionally when reading
Type of Change
Testing
Manually.
Checklist