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
key_ identifier.live or test; part of the key's prefix.The first characters of the secret, for recognising it.
Reserved for finer permissions; accepted and stored, not yet enforced.
Updated on every authenticated request.
Only on creation.
{
"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
/v1/api-keysSession token onlyEvery key in the organization, newest first, including revoked and expired ones. Returns a bare array, not a page.
Returns
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"[
{
"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
/v1/api-keysSession token onlyCreate a key and return its secret once. Counts against the API keys quota and the 20-per-hour limit.
Body parameters
1 to 120 characters.
live or test.Reserved.
1 to 3650. Omit for a key that does not expire.
Returns
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 againcurl 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}'{
"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
/v1/api-keys/{key_id}Session token onlyRevoke 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
Returns
client.api_keys.revoke("key_6f2a151d6e1cd7ca3c8f")curl -X DELETE https://api.kaimei.ai/v1/api-keys/key_6f2a151d6e1cd7ca3c8f \
-H "Authorization: Bearer $SESSION_TOKEN"{
"id": "key_6f2a151d6e1cd7ca3c8f",
"object": "api_key",
"deleted": true
}