The cost of using the OpenAI ChatGPT API is calculated based on the number of tokens processed in both the input and output. Each API request returned by ChatGPT includes a “usage” field that indicates the total number of tokens used.
The cost is as follows: Cost = Number of tokens used × Cost per token (specified by OpenAI)
A token can be as short as one character or as long as one word. For example, “ChatGPT is great!” is encoded into six tokens: [“Chat”, “G”, “PT”, “ is”, “ great”, “!”].
For detailed information on pricing, you should check the OpenAI Pricing page. Make sure you monitor your usage to ensure it aligns with your expected costs.