💹 Introducing the Usage API—track API usage and costs programmatically

Today we’re launching a new API that lets you get granular API usage data, and a Costs endpoint that provides you with a breakdown of your daily spend. You can monitor token use by minute/hour/day, filter usage by API key, project ID, user ID, model. https://platform.openai.com/docs/api-reference/usage

14 Likes

OpenAI has a new Usage API that lets you track API usage and costs programmatically.

:eyes: Monitor tokens by minute/hour/day
:mag_right: Filter usage by API key, project ID, user ID, model, and more
:chart: Check daily spend via the Costs endpoint

12 Likes

Nice! Lots of people have been asking for this for a while now!

8 Likes

Thanks also for killing off the “other models” idea in “usage”, in which the billing for everything useful was clustered for obfuscation…

Models by name are back.

1 Like

@edwinarbus looks like API keys require a new api.usage.read scope in order to use this new Costs API. I can’t seem to enable this scope for any new keys I create.

Is there something that needs to be enabled on an account in order to use this new API?
Example request:

curl "https://api.openai.com/v1/organization/costs?start_time=1730419200&limit1" -H "Authorization: Bearer [api-key]"

Example response:

{
  "error" : {
    "message": "You have insufficient permissions for this operation. Missing scopes: api.usage.read. […]",
    "type": "servier_error",
    "param": null,
    "code" : null
  }
}

In case anyone else is hitting this, the new /costs API requires an admin key, not an API key. :man_facepalming:

2 Likes

This topic was automatically closed after 11 days. New replies are no longer allowed.