I wrote a command line tool using nodejs, ref: https://community.openai.com/t/use-cli-to-batch-download-the-usage-data-of-openai-api/127734
Note that the usage data given by openai may exceed expectations. For example, I saw a message about using 152k tokens last month. Someone explained it here, but it is still very strange. ref: https://community.openai.com/t/what-is-n-context-tokens-total-why-is-it-so-large/127420