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.