1/16
Learn

Pricing an LLM feature, the way the ML round asks

An Airbnb ML round asked candidates to trade off precision, recall, latency and infrastructure cost (1 report). For an LLM feature, the cost side comes down to three questions, and this lesson's practice problem answers them in code, in three levels:

  1. request_cost(price, input_tokens, output_tokens, read, write, ttl): what one request costs, with cached input priced as a read or a write.
  2. hit_rate(per_hour, ttl_minutes), expected_cost(...) and best_ttl(...): what caching the shared prompt saves at a given traffic, and which cache lifetime to buy.
  3. cheaper(api_per_mtok, hourly, capacity_tps, demand_tps): whether renting GPUs beats paying per token.
CallReturns
request_cost(sonnet, 1860, 250)0.00622 dollars
hit_rate(6, 5)0.393 of requests hit
best_ttl(sonnet, 1800, 60, 250, 0.5)"none": too rare to cache
cheaper(0.50, 4.89, 22_852, 350)("api", 0.63): the API, at 63 cents an hour

The lesson follows the outdoor shop's support assistant at 3.6 million questions a month: one request's price, caching the shared prompt, routing and batching, and renting GPUs. Seven steps end with a small task in the editor.