Skip to content
Primary navigation

List project API keys

admin.organization.projects.api_keys.list(strproject_id, APIKeyListParams**kwargs) -> SyncConversationCursorPage[ProjectAPIKey]
GET/organization/projects/{project_id}/api_keys

Returns a list of API keys in the project.

ParametersExpand Collapse
project_id: str
after: Optional[str]

A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.

limit: Optional[int]

A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.

ReturnsExpand Collapse
class ProjectAPIKey: …

Represents an individual API key in a project.

id: str

The identifier, which can be referenced in API endpoints

created_at: int

The Unix timestamp (in seconds) of when the API key was created

formatunixtime
last_used_at: Optional[int]

The Unix timestamp (in seconds) of when the API key was last used.

formatunixtime
name: str

The name of the API key

object: Literal["organization.project.api_key"]

The object type, which is always organization.project.api_key

owner: Owner
service_account: Optional[OwnerServiceAccount]

The service account that owns a project API key.

id: str

The identifier, which can be referenced in API endpoints

created_at: int

The Unix timestamp (in seconds) of when the service account was created.

formatunixtime
name: str

The name of the service account.

role: str

The service account’s project role.

type: Optional[Literal["user", "service_account"]]

user or service_account

One of the following:
"user"
"service_account"
user: Optional[OwnerUser]

The user that owns a project API key.

id: str

The identifier, which can be referenced in API endpoints

created_at: int

The Unix timestamp (in seconds) of when the user was created.

formatunixtime
email: str

The email address of the user.

name: str

The name of the user.

role: str

The user’s project role.

redacted_value: str

The redacted value of the API key

List project API keys

import os
from openai import OpenAI

client = OpenAI(
    admin_api_key=os.environ.get("OPENAI_ADMIN_KEY"),  # This is the default and can be omitted
)
page = client.admin.organization.projects.api_keys.list(
    project_id="project_id",
)
page = page.data[0]
print(page.id)
{
    "object": "list",
    "data": [
        {
            "object": "organization.project.api_key",
            "redacted_value": "sk-abc...def",
            "name": "My API Key",
            "created_at": 1711471533,
            "last_used_at": 1711471534,
            "id": "key_abc",
            "owner": {
                "type": "user",
                "user": {
                    "id": "user_abc",
                    "name": "First Last",
                    "email": "user@example.com",
                    "role": "owner",
                    "created_at": 1711471533
                }
            }
        }
    ],
    "first_id": "key_abc",
    "last_id": "key_xyz",
    "has_more": false
}
Returns Examples
{
    "object": "list",
    "data": [
        {
            "object": "organization.project.api_key",
            "redacted_value": "sk-abc...def",
            "name": "My API Key",
            "created_at": 1711471533,
            "last_used_at": 1711471534,
            "id": "key_abc",
            "owner": {
                "type": "user",
                "user": {
                    "id": "user_abc",
                    "name": "First Last",
                    "email": "user@example.com",
                    "role": "owner",
                    "created_at": 1711471533
                }
            }
        }
    ],
    "first_id": "key_abc",
    "last_id": "key_xyz",
    "has_more": false
}