Finally got around to trying to reconcile my internal token usage records with those generated by OpenAI. Sheesh!
So, on the usage dashboard, you see something like this:
And, if you call to the API: https://api.openai.com/v1/usage?date=2023-09-07
You get:
Even less helpful. And, what’s up with that timestamp?
The timestamp 1694044800 translates to:
Thursday, January 12, 2023 12:00:00 AM UTC
So in UTC time, that timestamp represents midnight on January 12, 2023.
To convert it to my local time:
I’m currently located in Pacific Time (UTC-8). So for me, that timestamp would be:
Wednesday, January 11, 2023 4:00:00 PM PST
Bizarre!
So, I keep track of token usage internally, which of course is far more detailed, but I’m trying to figure out how to square that with the token usage OpenAI records.
Any suggestions?
How are you recording token usage? there should be a 1:1 relationship.
Typically, I total the tokens used in one query call. So, tokens used for for API calls for concept, standalone and anything else, including the completion, that is involved in bringing back single query result for a single user. But, the numbers and times I see in the dashboard don’t appear to mesh with my calculations. Perhaps a better question is how is OpenAI logging the tokens used?
By one-to-one, what do you mean? And, what is meant by “local time”?
Let’s say 9-7-2023, 1:00am. When I look at my log for that time and compare with OpenAI, I don’t see where it’s getting it’s totals. And, I can’t even figure out how to read the timestamps in the usage object returned by the API call.to the usage endpoint.
Help!
I’m not sure if OAI add any offsets, if not the time will be UNIX epoch format, you can translate that via
import datetime
timestamp = 1640995200
dt_object = datetime.datetime.fromtimestamp(timestamp)
print(dt_object)
OpenAI just total up the received and sent tokens for any given API call, note that if you have made an API call but did not get a response back, that may still be counted as tokens used if the call was processed on OAI’s end.
I’ve not found any discrepancies’ so far in my usage, other than the odd API comms error causing my count to be either a little higher or a little lower, it’s typically under 1% error, so for accountancy purposes you have done due diligence.
1 Like
Last question. Is this the correct usage to connect to the API?
https://api.openai.com/v1/usage?date=2023-09-07
The unix epoch timestamps returned don’t seem to match the date entered.
Thanks!
I’ll be honest, I did not even know there was a usage API, I’ve either missed it, or it’s undocumented.