1. Learn
  2. /
  3. Courses
  4. /
  5. Working with the OpenAI API

Connected

Exercise

Calculating the cost

Before deploying AI features at scale, it's essential to estimate costs. The cost is dependent on the number of input and output tokens used and the model chosen.

Your task is to calculate the cost of summarizing customer chat transcripts.

The OpenAI client, along with text, prompt, and max_completion_tokens, are preloaded for you.

Instructions

100 XP
  • Extract the input token usage from the response.
  • Complete the cost calculation to add the output token cost.