Is there a way to get this API key-level usage more programmatically through a usage endpoint? Not much point in having separate API keys for different teams if the only way to view usage is through an unconfigurable dashboard…
In the api.openai.com/v1/usage endpoint I see new inner fields for api_key_id and api_key_name but they seem to always be null. Would be really helpful if they were filled in or if there was a way to query usage by API key ID/name
Based on pointers in this thread, I’ve created a small Python script that can fetch and compute API usage and cost by API key and model, as well as input and output tokens.
One catch is that you need to get and enter in your session key from the request that your browser makes (ie. the network requests tab in your Chrome console). Thankfully, I’ve noticed that the session key is quite stable for me (doesn’t change across days).
Please leave any comments / I’m open to any feedback on the gist directly. Thanks!
perhaps you’ve noticed already, but on the API key page, you need to individually enable tracking per API key for older API keys - this is why you’re taken to this page from the “turn on tracking” link. New API keys are tracked by default.
Robertsmania, please explain how do you get visibility to cost by user? I haven’t yet used Project keys (that’s a project for this week - pun intended) but in all the reading I’ve done I only see costs by Organization and by Project. What did I miss where?
On my usage page it is broken down by Top Users, Top Organizations, Top Projects, Top API keys. Perhaps that detail does not show up until you start using Project keys.
You cannot see cost per API directly but you can create multi project for each API KEY you want to manage. Then you can export and see the cost per project.