Skip to main content
POST
/
org
/
api_keys
/
{id}
/
rotate
JavaScript
import Kernel from '@onkernel/sdk';

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

const createdAPIKey = await client.apiKeys.rotate('id');

console.log(createdAPIKey);
{
  "id": "ckv9w8q2f000001l5r3j7k9m4",
  "name": "production",
  "created_at": "2023-11-07T05:31:56Z",
  "created_by": {
    "id": "user-abc123",
    "email": "user@example.com",
    "name": "Jane Doe"
  },
  "expires_at": "2023-11-07T05:31:56Z",
  "deleted_at": "2023-11-07T05:31:56Z",
  "project_id": "proj_abc123",
  "project_name": "Production",
  "masked_key": "sk_1234...abcd",
  "key": "sk_1234abcd"
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Path Parameters

id
string
required

API key ID

Body

application/json
days_to_expire
integer | null

Lifetime in days for the new key, up to 3650. Omit to reuse the rotated key's original lifetime, or never-expires if it had none.

Required range: 1 <= x <= 3650
Example:

30

expire_in_days
integer | null

Grace period in days before the rotated key expires. Use 0 to expire it immediately. Omit for the default grace period of 7 days.

Required range: 0 <= x <= 3650
Example:

7

Response

New API key created from the rotation

API key returned immediately after creation. Includes the plaintext key once.

id
string
required

Unique API key identifier

Example:

"ckv9w8q2f000001l5r3j7k9m4"

name
string
required

API key name

Example:

"production"

created_at
string<date-time>
required

When the API key was created

created_by
object
required
expires_at
string<date-time> | null
required

When the API key expires

deleted_at
string<date-time> | null
required

When the API key was deleted (soft-deleted). Null for keys that have not been deleted.

project_id
string | null
required

Project identifier for project-scoped API keys. Null means org-wide.

Example:

"proj_abc123"

project_name
string | null
required

Project name for project-scoped API keys. Null means the key is org-wide or the project name is unavailable.

Example:

"Production"

masked_key
string
required

Masked version of the API key

Example:

"sk_1234...abcd"

key
string
required

Plaintext API key. Only returned once when the key is created.

Example:

"sk_1234abcd"