API keys

API keys

Create, list and revoke the credentials your servers and notebooks use.

Credentials for the organization. These endpoints need a signed-in session; keys cannot manage keys. The free plan allows 5 active keys.

#The API key object

The secret appears once, in the response that creates the key. Afterwards only the prefix identifies it.

Attributes

idstring
key_ identifier.
namestring

environmentstring
live or test; part of the key's prefix.
prefixstring

The first characters of the secret, for recognising it.

scopesarray of strings

Reserved for finer permissions; accepted and stored, not yet enforced.

last_used_attimestamp | null

Updated on every authenticated request.

expires_at / revoked_attimestamp | null

created_attimestamp

secretstring

Only on creation.

POST /v1/api-keys response
{
  "object": "api_key",
  "id": "key_6f2a151d6e1cd7ca3c8f",
  "name": "CI pipeline",
  "environment": "live",
  "prefix": "km_live_fPaB",
  "scopes": [],
  "last_used_at": null,
  "expires_at": "2027-01-29T22:40:22.818479Z",
  "revoked_at": null,
  "created_at": "2026-10-31T22:40:22.819488Z",
  "secret": "km_live_fPaBvCL6kRW9pi7Uve-1fzLD9s3HP8mO"
}

#List API keys

GET/v1/api-keysSession token only

Every key in the organization, newest first, including revoked and expired ones. Returns a bare array, not a page.

Returns

An array of API key objects.
client.auth.login(email="[email protected]", password="...")
for key in client.api_keys.list():
    print(key.name, key.prefix, key.environment, key.last_used_at, key.revoked_at)
curl https://api.kaimei.ai/v1/api-keys \
  -H "Authorization: Bearer $SESSION_TOKEN"
200 OKResponse
[
  {
    "object": "api_key",
    "id": "key_6f2a151d6e1cd7ca3c8f",
    "name": "CI pipeline",
    "environment": "live",
    "prefix": "km_live_fPaB",
    "scopes": [],
    "last_used_at": null,
    "expires_at": "2027-01-29T22:40:22.818479Z",
    "revoked_at": null,
    "created_at": "2026-10-31T22:40:22.819488Z"
  },
  {
    "object": "api_key",
    "id": "key_9df225436f5149d1494c",
    "name": "Notebook",
    "environment": "test",
    "prefix": "km_test_T8aL",
    "scopes": [],
    "last_used_at": "2026-10-31T22:40:22.813671Z",
    "expires_at": null,
    "revoked_at": null,
    "created_at": "2026-10-31T22:37:25.380781Z"
  }
]

#Create an API key

POST/v1/api-keysSession token only

Create a key and return its secret once. Counts against the API keys quota and the 20-per-hour limit.

Body parameters

namestringrequired

1 to 120 characters.

environmentstringoptionaldefault "live"
live or test.
scopesarray of stringsoptional

Reserved.

expires_in_daysintegeroptional

1 to 3650. Omit for a key that does not expire.

Returns

The API key with its secret. 201.
key = client.api_keys.create(name="CI pipeline", environment="live", expires_in_days=90)
print(key.secret)      # store it now; it is not shown again
curl https://api.kaimei.ai/v1/api-keys \
  -H "Authorization: Bearer $SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "CI pipeline", "environment": "live", "expires_in_days": 90}'
201 CreatedResponse
{
  "object": "api_key",
  "id": "key_6f2a151d6e1cd7ca3c8f",
  "name": "CI pipeline",
  "environment": "live",
  "prefix": "km_live_fPaB",
  "scopes": [],
  "last_used_at": null,
  "expires_at": "2027-01-29T22:40:22.818479Z",
  "revoked_at": null,
  "created_at": "2026-10-31T22:40:22.819488Z",
  "secret": "km_live_fPaBvCL6kRW9pi7Uve-1fzLD9s3HP8mO"
}

#Revoke an API key

DELETE/v1/api-keys/{key_id}Session token only

Revoke a key immediately. Requests with it fail with 401 invalid_api_key from then on. The record stays in the list with revoked_at set.

Path parameters

key_idstringrequired

Returns

A deletion receipt.
client.api_keys.revoke("key_6f2a151d6e1cd7ca3c8f")
curl -X DELETE https://api.kaimei.ai/v1/api-keys/key_6f2a151d6e1cd7ca3c8f \
  -H "Authorization: Bearer $SESSION_TOKEN"
200 OKResponse
{
  "id": "key_6f2a151d6e1cd7ca3c8f",
  "object": "api_key",
  "deleted": true
}