Estimating ChatGPT API Costs

A simple way to estimate API costs is to measure the tokens in a representative prompt and response, check the model’s per-token pricing, and multiply by the expected number of records.

1. Prepare an input prompt and output example

First, save the input prompt and an example of the expected output.

  • Input prompt: This is a set of categories for questions related to tuberculosis medication. 1. Side effects 2. Drug resistance 3. Effectiveness 4. Alcohol/smoking/how to take medication 5. Interactions with other medications 6. Infectiousness/stigma/isolation while taking medication 7. Military service 8. Recurrence 9. Translation 10. Other Instructions: Classify the input question into the appropriate category. Write the reasoning for your decision before stating the category. Classify it into only one most appropriate category. If it does not fall under any category, classify it as 10. Other. If it falls under 9. Translation, do not perform the actual translation. Follow the output format strictly. Begin the response with “Reasoning:”. Output format: Reasoning: <State the basis for the category classification in one sentence> Category: <Output the single most relevant category> Example Input Question: Since this morning, I have taken one Tubist tablet and one pyridoxine tablet for latent tuberculosis. By the afternoon, my head felt foggy, I had no energy, and I felt unwell as if I had body aches. What should I do? Can I stop taking the medicine? Output Reasoning: The question asks about physical abnormal reactions, including a “foggy head” and “lack of energy,” after taking medication, so it concerns side effects. Category: 1. Side effects
  • Input Question: Tuberculosis medicine and alcohol: Is it really not okay to drink even a single glass while taking tuberculosis medicine? Output Reasoning: The question asks whether alcohol consumption is permitted while taking tuberculosis medication, so it concerns alcohol/smoking/how to take medication. Category: 4. Alcohol/smoking/how to take medication

2. Check the token count

Next, check how many tokens the input text is recognized as containing. This can be checked at https://platform.openai.com/tokenizer.

Although the Korean tokenizer for 4o has improved considerably and the actual count may be lower, assume conservatively that the input is 629 tokens and the output is 94 tokens.

3. Check the price per 1 million tokens

Pricing is available at https://openai.com/api/pricing/.

For example, when using the 4o-0806 model, the input price is $2.50 per 1 million tokens and the output price is $10 per 1 million tokens.

4. Multiply by the expected volume

If 40,000 records are analyzed using the prompt above, the estimated input cost is:

40,000 × 629 × $2.50 / 1,000,000 = $62.90

The estimated output cost is:

40,000 × 94 × $10 / 1,000,000 = $37.60

The total estimated cost is therefore about $100.

  • Estimated input cost: $62.90
  • Estimated output cost: $37.60
  • Estimated total cost: about $100

Summary

This is how to estimate the cost: obtain a representative prompt and output example, count their tokens, check the model’s token pricing, and multiply the result by the number of records to be processed.