Accessing OpenAI billing metrics via API

Hello,

I want to view real-time billing metrics all in one place on my website, so it would be very helpful if I could access my OpenAI billing through an API.

Thanks

“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