Is there any API to fetch usage data?

Currently we can check usage data from the portal.
But, I didn’t find any API to fetch the same data.

I am planning this: Build an anomaly detection tool on usage.

  1. List all api key descriptions and user email address who created the api key: based on organization id
  2. Fetch usage data day-wise by api key
  3. Check if any unusual surge in the usage
  4. Notify the org owners to take action

There is no API for that purpose specifically.

Although you can calculate costs by the token consumption returned by API calls when calling the models. It gives you prompt_tokens and completion_tokens separately.

Or are trying to create a tool for API key management/billing optimization?

1 Like

@cdonvd0s is correct that there is no API for that purpose specifically.
You would need to implement a gateway which will enable you to track the metrics.

If you are trying to build an anomaly detection tool for users to get notified about any unusual usage of API keys (great idea btw) you can use the following workflow.

Steps Description Tools/Links
1 Use a web scraping service to download the usage data ScrapingBee or Apify
2 Download the data as csv/json from the usage portal OpenAI Usage Portal (Activity Section)
3 Run your anomaly detection code -

Thank you! That is good workflow. I will implement that.

1 Like