PIXELBANKv9.1.0
Menu

Dollar Cost of a Token-Priced Call

Problem Statement

Compute the dollar cost of an LLM call given separate per-million prices for input and output tokens.

Background

Providers price input and output tokens differently, quoted per million tokens. The cost is **(input_tokens/1e6)input_price + (output_tokens/1e6)output_price.

Your Task

def call_cost(input_tokens, output_tokens, input_price, output_price):

Return the cost in dollars, rounded to 6 decimals.

Input Format

  • input_tokens, output_tokens (int); input_price, output_price (float, per 1M tokens).

Output Format

  • A float rounded to 6 decimals.

Sample

print(call_cost(1000, 500, 3.0, 15.0))

Output:

0.0105

Example:

Input:
print(call_cost(1000, 500, 3.0, 15.0))
Output:
0.0105
Reasoning:
  • Calculate the cost for input tokens by dividing the token count by one million to normalize the unit, then multiplying by the per-million price: 10001,000,000×3.0=0.001×3.0=0.003\frac{1000}{1,000,000} \times 3.0 = 0.001 \times 3.0 = 0.003 dollars.
  • Calculate the cost for output tokens using the same normalization and the higher output price: 5001,000,000×15.0=0.0005×15.0=0.0075\frac{500}{1,000,000} \times 15.0 = 0.0005 \times 15.0 = 0.0075 dollars.
  • Sum the input and output costs to determine the total expense for the call: 0.003+0.0075=0.01050.003 + 0.0075 = 0.0105 dollars.
  • Round the total cost to 6 decimal places as required by the output format; since the value is already exact, it remains 0.01050.0105.
  • The final output is 0.0105

Constraints:

  • Prices are per 1,000,000 tokens.
  • Cost = in/1e6in_price + out/1e6out_price.
  • Round to 6 decimals.
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.