How to Determine Token Usage Per Call and Total Post-Run in OpenAI API?

How to Determine Token Usage Per Call and Total Post-Run in OpenAI API?

Hi everyone,

I’m working with the OpenAI API and looking to monitor token usage in two specific ways: per API call and the total usage after an entire run. I haven’t been able to find information on accessing this data directly from the API responses or the documentation. Is there a way to retrieve these details? Alternatively, I’ve thought about using some existing code to estimate token numbers based on input length for each call. Does anyone have experience with this, or can you recommend better strategies for tracking both individual and total token usage accurately?

Thanks for your insights!