Skip to content

fix(usage): persist cost multiplier at provider level instead of also at the logger level#1433

Merged
waleedlatif1 merged 3 commits intostagingfrom
fix/apply-cost-multiplier-at-storage
Sep 24, 2025
Merged

fix(usage): persist cost multiplier at provider level instead of also at the logger level#1433
waleedlatif1 merged 3 commits intostagingfrom
fix/apply-cost-multiplier-at-storage

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

persist cost with multiplier at provider level instead of conditionally when reading

Type of Change

  • Bug fix

Testing

Manually.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Sep 23, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
sim Error Error Sep 23, 2025 11:44pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Sep 23, 2025 11:44pm

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

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 totalCost directly 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
Loading

3 files reviewed, no comments

Edit Code Review Bot Settings | Greptile

@waleedlatif1 waleedlatif1 merged commit 0d86eaa into staging Sep 24, 2025
5 of 6 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/apply-cost-multiplier-at-storage branch September 25, 2025 22:39
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