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.

In an organization a key belongs to the workspace but answers to the person who created it. When they are removed or leave, their keys are revoked. While they are a viewer, their keys only read (403 read_only_role on a write) and work fully again once they are a member. Keys in a personal workspace are the account's own.

#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

Empty means the key can do everything. Otherwise read, write, or resource:read / resource:write for models, predictions, explanations, analyses, insights, projects, or organization. write includes read. A call outside the list is 403 insufficient_scope.

last_used_attimestamp | null

Updated on every authenticated request.

expires_at / revoked_attimestamp | null

created_attimestamp

created_by_user_idstring | null

The account that created the key. null for a key made before this was recorded or by an account that no longer exists.

created_by_name / created_by_emailstring | null

That account's name and email. They stay after the person leaves, so an admin can see whose keys were revoked.

secretstring

Only on creation.

POST /v1/api-keys response
{
  "object": "api_key",
  "id": "key_6f2a151d6e1cd7ca3c8f",
  "name": "CI pipeline",
  "environment": "live",
  "prefix": "km_live_EXAM",
  "scopes": [],
  "last_used_at": null,
  "expires_at": "2027-01-29T22:40:22.818479Z",
  "revoked_at": null,
  "created_at": "2026-10-31T22:40:22.819488Z",
  "created_by_user_id": "usr_99d45281ca85b8a7cc92",
  "created_by_name": "Kaimei Demo",
  "created_by_email": "demo@kaimei.ai",
  "secret": "km_live_EXAMPLEnotARealKeyUseYourOwn0000"
}

#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.

Query parameters

created_bystringoptional

A user_id. Only the keys that account created here, revoked ones included, also after the person has left.

Returns

An array of API key objects.
client.auth.login(email="you@example.com", 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_EXAM",
    "scopes": [],
    "last_used_at": null,
    "expires_at": "2027-01-29T22:40:22.818479Z",
    "revoked_at": null,
    "created_at": "2026-10-31T22:40:22.819488Z",
    "created_by_user_id": "usr_99d45281ca85b8a7cc92",
    "created_by_name": "Kaimei Demo",
    "created_by_email": "demo@kaimei.ai"
  },
  {
    "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",
    "created_by_user_id": "usr_99d45281ca85b8a7cc92",
    "created_by_name": "Kaimei Demo",
    "created_by_email": "demo@kaimei.ai"
  }
]

#Create an API key

POST/v1/api-keysSession token only

Create a key and return its secret once. The key acts in the organization the session is working in. Counts against the API keys quota and the hourly limit (20 on the free plan). A viewer cannot create one (403 read_only_role).

Body parameters

namestringrequired

1 to 120 characters.

environmentstringoptionaldefault "live"
live or test.
scopesarray of stringsoptional

Empty can do everything. Otherwise read, write, or models:read and the same form for the other resources. An unknown scope is 400 invalid_scope.

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_EXAM",
  "scopes": [],
  "last_used_at": null,
  "expires_at": "2027-01-29T22:40:22.818479Z",
  "revoked_at": null,
  "created_at": "2026-10-31T22:40:22.819488Z",
  "created_by_user_id": "usr_99d45281ca85b8a7cc92",
  "created_by_name": "Kaimei Demo",
  "created_by_email": "demo@kaimei.ai",
  "secret": "km_live_EXAMPLEnotARealKeyUseYourOwn0000"
}

#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. A member may revoke the keys they created, and an owner or admin any key (403 admin_required otherwise). Revoking your own key works whatever your role, a viewer's or a paused organization's included, so a leaked key can always be stopped. A key is also revoked when the person who created it leaves the organization.

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
}