I don't know if this is allowed, but you can reverse engineer the dashboard page, and then you get this endpoint:
https://api.openai.com/dashboard/billing/usage?start_date=YYYY-MM-DD&end_date=YYYY-MM-DD
You can adjust the dates in the query parameters to your needs in the following format: YYYY-MM-DD, e.g.
https://api.openai.com/dashboard/billing/usage?end_date=2024-01-01&start_date=2023-12-01
In the headers you will need to include your token and organization, here's how the headers object looks like:
{
"Openai-Organization": "YOUR_ORGANIZATION_ID",
"Authorization": "Bearer YOUR_TOKEN"
}
- To get your organization ID, go to the organization page and copy your organization ID, this looks something like
org-abc123 - To get your token:
- Go to a random page on the openai platform, e.g. the playgrond
- Open up developer tools by clicking
F12or right clicking on the page and selectinginspect - Navigate to the
networktab, this is the fourth tab. - Reload the page
- Hit
ctrl+f - Type
Bearer sessin the search bar - Hit
enter, and you'll see a couple results, click on one of them, and your token should be highlighted on the screen.