I have a project with 8 different keys. I am not able to view the API usage by keys. All the usage page shows is the usage by gpt model or by project. How / Where do I get this info?
The usage information per API key can be a bit confusing. In the attached screenshot, the section circled in red shows the usage per API key, although initially the display shows usage per user.
By switching, you can view the information on usage per API key.
On other screens, such as the “Usage > Chat Completions” screen, the tabs are divided into “Models,” “Users,” “Projects,” and “API Keys.”
Initially, usage per model is displayed, but by switching, you can see the usage per API key.
Thanks, found it. However, the keys that I see here are not the names of the keys that I have, niether are they the actual keys - they are named something like - key_sq*** . I have no idea what key this reference corresponds to. Where can I find which keys these labels are referring to?
Thanks, found it. However, the keys that I see here are not the names of the keys that I have, niether are they the actual keys - they are named something like - key_sq*** . I have no idea what key this reference corresponds to. Where can I find which keys these labels are referring to?
What is displayed here is not the API key itself, but rather the API key’s ID.
You can only view the entire API key (the secret) at the time it is created, and cannot view it again thereafter.
However, from the last few characters of the API key and the name you assigned to the API key, you can determine which API key (secret) corresponds to which API key ID.
Here, we assume that as an organization, you create and use your API keys under a specific project.
First, if you have not yet created an admin API key, please create one.
An admin API key is a long string that begins with sk-admin-.
Next, find the project name you used when creating your API key.
As shown in the attached screenshot, there is a project ID that corresponds to the project name, so copy and use that project ID.
If you are on Windows PowerShell, you can run the script below to retrieve a list (up to 20 items) of the following for each API key in the project:
- The beginning of the API key (sk-proj-)
- The last four characters of the API key
- The API key ID (key_ + 16 characters)
- The name you assigned to the API key
If you have created more than 20 API keys, please adjust the limit parameter accordingly.
Also, replace {Projects_ID_goes_here} with the actual project ID.
$uri = "https://api.openai.com/v1/organization/projects/{Projects_ID_goes_here}/api_keys?&limit=20"
$apiKey = "sk-admin-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
$headers = @{
"Authorization" = "Bearer $apiKey"
"Content-Type" = "application/json"
}
Invoke-RestMethod -Uri $uri -Headers $headers -Method Get
Example Output:
object : list
data : {@{object=organization.project.api_key; redacted_value=sk-proj-*********************************************
***************************************************************************7bcU; id=key_dDA9EwHwp8CoMXXXX; na
me=Google Colab; created_at=1725467288; owner=}, @{object=organization.project.api_key; redacted_value=sk-pr
oj-*********************************************************************************************************
***********************************************9wLh; id=key_mKkGeFi7ShWKVXXXX; name=Windoes 11; created_at=17
26608836; owner=}, @{object=organization.project.api_key; redacted_value=sk-proj-***************************
************************************************************************************************************
*****************53So; id=key_sq2Qz4jH56NHNXXXX; name=Google Colab; created_at=1727325518; owner
=}, @{object=organization.project.api_key; redacted_value=sk-proj-******************************************
************************************************************************************************************
**WKt9; id=key_96eSVqqwVMw2gFXXXX; name=Google Colab2; created_at=1733996499; owner=}...}
first_id : key_dDA9EwHwp8CoMXXXX
last_id : key_96eSVqqwVMw2gFXXXX
has_more : False
Even if you do not know the API key (secret) directly, you should be able to determine which API key (secret) corresponds to which API key ID by looking at the last four characters or the name you assigned to the API key.
Thanks for the answer! And thanks to OpenAI for making it so easy :sarcasm:
To be fair to OpenAI almost all services hide your keys once you create them (as they should!)
Is there any way to find the API key’s id without using an admin key?
Like a simpler way? There has to be some way to check, because from my own checking I couldn’t find a single similar thing between the API key’s id and the actual API key.
No. You are incorrect. This is not about hiding secret keys, this is about a bug in the OpenAI new ui.
We can verify this by clicking the link “View legacy dashboard” - which shows the API keys by (user assigned) name. The new dashboard is broken/incorrect, displaying the internal key-id which is visible nowhere. This was a mistake by whoever implemented the new dashboard.
it’s really complex, no way to match unless i create a project for each apikey.
So instead of joining the user defined name (which has no relevance otherwise) on the openai server side, we should create an admin key and run scripts to find out which keys are used.
This is nonsense.
It is just a quick workaround, not a solution, right?
UPDATE: I was able to find the Organization section and Admin Key item in the sidebar, but I had to visit a different page from the usage page for it to show up.
This is what it looks like on the Usage page: no Organization section or Admin Key item.
But when I clicked on my picture in the upper right and then “Your Profile”, then the sidebar had those items. (The text editor won’t let me add a second picture, but it does have Organization and Admin Keys in the sidebar.)
This is way more complicated than it should be!
Original message below:
I’m facing the same problem, but because I created some keys under a personal account, I don’t see any way to create an admin key. The sidebar of my dashboard page looks different from the screenshot @dignity_for_all posted. It doesn’t have an admin key item.
Is there any way for me to find out how much money each key is costing? All I want is to match up the name of the key to the key ID.
It looks like your screenshot shows the dashboard.
If you wish to view the usage of API keys created under your personal account, click the gear icon (Settings) in the top-right corner.
If you want to view the usage of API keys created under an organization account, click “Personal” at the top of the page, switch to your organization account, and then click the same gear icon (Settings).
This opens the Admin keys tab.
Personal and organization accounts use separate Admin keys, so a key from one account cannot be used to view API key usage in the other. However, in practice, even personal accounts have an organization ID, so it may be clearer to see the personal-versus-organization distinction mainly as a difference in how it is shown in the UI.
Hope this helps!
I was able to find it using a quick hack. If you inspect the api keys window using firefox (or chrome - really any browser), you will see a call to get the api key information in the network tab:
I just copy the entire json string and save it to a file for later reference.
Paul_Wright is absolutely right, the data is all available in plain text in the usage page, OpenAI just refuses to show directly which key it is.
What @dignity_for_all shared is not necessary at all, if OpenAI would display the information about the key that is already available in plain text!
open32422lk2 is correct, this is a bug, which can be easily solved by OpenAI if they wanted to.
This worked Paul! Clearly there is a bug in the dashboard display.