lesson 2 of 4 · read the token bill — what your llm feature actually costsread the token bill — what your llm feature actually costsread the token bill — what your llm feature actually costslesson 2 of 4 · read the token bill — what your llm feature actually costsread the token bill — what your llm feature actually costsread the token bill — what your llm feature actually costslesson 2 of 4 · read the token bill — what your llm feature actually costsread the token bill — what your llm feature actually costsread the token bill — what your llm feature actually costslesson 2 of 4 · read the token bill — what your llm feature actually costsread the token bill — what your llm feature actually costsread the token bill — what your llm feature actually costslesson 2 of 4 · read the token bill — what your llm feature actually costsread the token bill — what your llm feature actually costsread the token bill — what your llm feature actually costslesson 2 of 4 · read the token bill — what your llm feature actually costsread the token bill — what your llm feature actually costsread the token bill — what your llm feature actually costslesson 2 of 4 · read the token bill — what your llm feature actually costsread the token bill — what your llm feature actually costsread the token bill — what your llm feature actually costslesson 2 of 4 · read the token bill — what your llm feature actually costsread the token bill — what your llm feature actually costsread the token bill — what your llm feature actually costslesson 2 of 4 · read the token bill — what your llm feature actually costsread the token bill — what your llm feature actually costsread the token bill — what your llm feature actually costslesson 2 of 4 · read the token bill — what your llm feature actually costsread the token bill — what your llm feature actually costsread the token bill — what your llm feature actually costslesson 2 of 4 · read the token bill — what your llm feature actually costsread the token bill — what your llm feature actually costsread the token bill — what your llm feature actually costs
Write estimate_call_cost(prompt, expected_output, in_rate, out_rate) that:
- Uses the
estimate_tokenshelper (chars / 4) to convert both strings to token counts. - Applies
in_rate(per 1M) to the prompt tokens. - Applies
out_rate(per 1M) to the expected_output tokens. - Returns the per-call cost as a float rounded to 6 decimals (these are fractions of a cent — precision matters when you multiply by a million calls).
Two scenarios run for you. Expected output:
sonnet 5 cost: $0.000240
opus 5 cost: $0.000600