Similar questions may be asked previously, but I did not find an answer for our case.
We have an application using ReactJS and NodeJS. We send GPT-3.5 and GPT-4 requests to OpenAI by openai.chat.completions.create and stream: true. We would like to count the tokens of prompts and complements as correct as possible to give a precise billing.
Does anyone know how to get or calculate this token usage? Which libraries can be used?
Yes, that to go along with the server that sends client software requests to OpenAI, so you don’t do silly things like putting API keys in your app to be stolen and have your account emptied.