Issue in fetching OpenAI API usage, billing cost, and credit balance programmatically for backend monitoring

Hi everyone,

I’m trying to fetch OpenAI API usage, billing cost, and credit balance programmatically for backend monitoring.

I tried calling the below endpoints.
GET /v1/usage
GET /v1/dashboard/billing/usage
GET /v1/dashboard/billing/credit_grants
GET /v1/dashboard/billing/subscription

But did not get any response from these endpoints.

You have given dashboard API endpoints, which are only for use by the platform site and a browser, with session key and bot validation checks. They are not for programmatic use.

You will need to use an organization admin API key in order to call administration API endpoints. Then consult the API reference for the calling methods and what resources are available.

You should code so that you get an error status code and body error message. This would reveal any faults in your calling technique, such as “not authorized!”

Hi,
Is it possible to get the usage details or credit balance info through calling an API for my ‘individual’ account API key or an admin key? Or is it only possible with organizational api keys?

The only API that directly deals with billings is “get costs”, delivering daily buckets of monetary use, which can be further broken down by individual project or by “line item” (model):

This, again, uses an admin API key, separately created by an owner in the platform profile.