๐Ÿš€ Everything is free โ€” help us improve! Submit feedback and shape the platform.
๐ŸงชTDD Challengeยทintermediateยทโฑ๏ธ 25โ€“40mยทโญ 150 XP

M-073Build a Per-Request Cost Tracker

Description

Nebula Corp's LLM spending is out of control โ€” they have no idea which features or users are driving costs. Build a cost tracking system that calculates per-request costs, aggregates by dimension (model, feature, user), and flags requests that exceed budget thresholds. The pricing table and trace data are provided, but the cost calculation and aggregation logic is missing.

Test Cases (3)

Calculates cost correctly
Should calculate cost from token counts and pricing
Input:calculateRequestCost('gpt-4o', 1000, 500)
Expected:CONTAINS:0.007
Groups by model
Should aggregate costs by model
Input:getCostByDimension('model')
Expected:CONTAINS:gpt-4o
Flags expensive requests
Should return requests above threshold
Input:flagExpensiveRequests(0.01)
Expected:CONTAINS:cost

Related Lessons

Click Run / Check to validate your solution