← Questions

Running cost of streamed token usage

0
AnthropicCodingLast asked Jul 2026

Token usage for model requests arrives as a stream of usage records rather than all at once. Compute what the usage costs, keeping the totals correct as each new record arrives, so the current cost can be read at any point without reprocessing the whole stream. Talk through how you would structure the per-record pricing and the running totals, and what the time and memory cost is per record.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding