Read the token bill — what your LLM feature actually costs — step 8 of 9
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 4.6 cost: $0.000360
opus 4.7 cost: $0.000600
⌘↵ runs the editor.read, then continue.
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 4.6 cost: $0.000360
opus 4.7 cost: $0.000600
this step needs the editor
on desktop today; in the app (coming soon). save your spot and we'll bring you back here when you're ready.