Skip to content
Primary navigation

List project API keys

client.admin.organization.projects.apiKeys.list(stringprojectID, APIKeyListParams { after, limit } query?, RequestOptionsoptions?): ConversationCursorPage<ProjectAPIKey { id, created_at, last_used_at, 4 more } >
GET/organization/projects/{project_id}/api_keys

Returns a list of API keys in the project.

ParametersExpand Collapse
projectID: string
query: APIKeyListParams { after, limit }
after?: string

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?: number

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

ReturnsExpand Collapse
ProjectAPIKey { id, created_at, last_used_at, 4 more }

Represents an individual API key in a project.

id: string

The identifier, which can be referenced in API endpoints

created_at: number

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

formatunixtime
last_used_at: number | null

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

formatunixtime
name: string

The name of the API key

object: "organization.project.api_key"

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

owner: Owner { service_account, type, user }
service_account?: ServiceAccount { id, created_at, name, role }

The service account that owns a project API key.

id: string

The identifier, which can be referenced in API endpoints

created_at: number

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

formatunixtime
name: string

The name of the service account.

role: string

The service account’s project role.

type?: "user" | "service_account"

user or service_account

One of the following:
"user"
"service_account"
user?: User { id, created_at, email, 2 more }

The user that owns a project API key.

id: string

The identifier, which can be referenced in API endpoints

created_at: number

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

formatunixtime
email: string

The email address of the user.

name: string

The name of the user.

role: string

The user’s project role.

redacted_value: string

The redacted value of the API key

List project API keys

import OpenAI from 'openai';

const client = new OpenAI({
  adminAPIKey: process.env['OPENAI_ADMIN_KEY'], // This is the default and can be omitted
});

// Automatically fetches more pages as needed.
for await (const projectAPIKey of client.admin.organization.projects.apiKeys.list('project_id')) {
  console.log(projectAPIKey.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
}