fix(cost): restored cost reporting for agent block in console entry#1253
fix(cost): restored cost reporting for agent block in console entry#1253waleedlatif1 merged 1 commit intostagingfrom
Conversation
There was a problem hiding this comment.
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:
-
Simplified
shouldBillModelUsagefunction (apps/sim/providers/utils.ts): The function signature was changed fromshouldBillModelUsage(model: string, userProvidedApiKey?: string)toshouldBillModelUsage(model: string), removing the API key parameter entirely. The logic now only checks if the model is in the hosted models list usinggetHostedModels().includes(model), eliminating the ambiguous API key check that was preventing proper cost tracking. -
Updated function call (
apps/sim/providers/index.ts): The call toshouldBillModelUsagewas updated to remove theapiKeyparameter, changing fromshouldBillModelUsage(response.model, request.apiKey)toshouldBillModelUsage(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.tsto ensure the simplified billing logic doesn't affect edge cases with non-hosted models
2 files reviewed, 1 comment
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-providedapi key, we incorrectly parsed our own keys as thatType of Change
Testing
Tested manually.
Checklist