promptdojo_

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_tokens helper (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

full-screen editor opens — close anytime to keep reading.