Quick Overview

Implement an exact usage calculator for language-model API requests with separate input and output token prices. Normalize streaming chunk deltas and non-streaming totals, reject malformed counts, avoid floating-point billing errors, and handle empty or very large workloads.

Calculate Streaming Token Usage Costs

Company: Anthropic

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

Overview: Implement an exact usage calculator for language-model API requests with separate input and output token prices. Normalize streaming chunk deltas and non-streaming totals, reject malformed counts, avoid floating-point billing errors, and handle empty or very large workloads.

Read the full Anthropic Software Engineer interview experience this question came from

Loading…