Skip to content
Primary navigation

Retrieve project API key

client.admin.organization.projects.apiKeys.retrieve(stringapiKeyID, APIKeyRetrieveParams { project_id } params, RequestOptionsoptions?): ProjectAPIKey { id, created_at, last_used_at, 4 more }
GET/organization/projects/{project_id}/api_keys/{api_key_id}

Retrieves an API key in the project.

ParametersExpand Collapse
apiKeyID: string
params: APIKeyRetrieveParams { project_id }
project_id: string

The ID of the project.

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

Retrieve project API key

import OpenAI from 'openai';

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

const projectAPIKey = await client.admin.organization.projects.apiKeys.retrieve('api_key_id', {
  project_id: 'project_id',
});

console.log(projectAPIKey.id);
{
    "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
        }
    }
}
Returns Examples
{
    "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
        }
    }
}