Skip to content

fix(cost): restored cost reporting for agent block in console entry#1253

Merged
waleedlatif1 merged 1 commit intostagingfrom
sim-68
Sep 5, 2025
Merged

fix(cost): restored cost reporting for agent block in console entry#1253
waleedlatif1 merged 1 commit intostagingfrom
sim-68

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

restored cost reporting for agent block in console entry, for hosted models we inject api key and in the check where we see if there is a user-provided api key, we incorrectly parsed our own keys as that

Type of Change

  • Bug fix

Testing

Tested 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 5, 2025

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

Project Deployment Preview Comments Updated (UTC)
sim Ready Ready Preview Comment Sep 5, 2025 4:17am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Sep 5, 2025 4:17am

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 Summary

This PR fixes a cost reporting bug for agent blocks in console entries by modifying the shouldBillModelUsage function to properly handle hosted models. The core issue was that the platform injects API keys for hosted models to enable communication with external providers, but the billing logic was incorrectly interpreting these platform-injected keys as user-provided keys, which would skip billing entirely.

The fix involves two key changes:

  1. Simplified shouldBillModelUsage function (apps/sim/providers/utils.ts): The function signature was changed from shouldBillModelUsage(model: string, userProvidedApiKey?: string) to shouldBillModelUsage(model: string), removing the API key parameter entirely. The logic now only checks if the model is in the hosted models list using getHostedModels().includes(model), eliminating the ambiguous API key check that was preventing proper cost tracking.

  2. Updated function call (apps/sim/providers/index.ts): The call to shouldBillModelUsage was updated to remove the apiKey parameter, changing from shouldBillModelUsage(response.model, request.apiKey) to shouldBillModelUsage(response.model).

The original design was intended to avoid billing users when they provide their own API keys (since they pay the provider directly), but it was incorrectly triggering for hosted models where the platform should bill for usage. This change ensures that hosted models are always billed regardless of API key source, while maintaining the platform's ability to provide seamless access to these models through injected credentials.

Confidence score: 4/5

  • This PR addresses a specific billing logic bug with a focused solution that should restore cost reporting functionality
  • Score reflects the targeted nature of the fix and clear problem identification, though the simplified logic removes some previous flexibility
  • Pay close attention to apps/sim/providers/utils.ts to ensure the simplified billing logic doesn't affect edge cases with non-hosted models

2 files reviewed, 1 comment

Edit Code Review Bot Settings | Greptile

@vercel vercel bot temporarily deployed to Preview – docs September 5, 2025 04:11 Inactive
@waleedlatif1 waleedlatif1 merged commit 53dd277 into staging Sep 5, 2025
4 of 5 checks passed
@waleedlatif1 waleedlatif1 deleted the sim-68 branch September 5, 2025 04:12
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