Accessing OpenAI billing metrics via API

“Billing metrics” is a rather ambiguous desire, but you can use the “costs” endpoint with an admin API key, that an owner can create in the platform site.

Here’s a quick Python script using that key set as environment variable to print a daily report by model (and yes, the API is currently working today):

It will give costs similar to the main page of “usage”, collected daily buckets that can lag behind a bit, but shows you dollar figures.

1 Like