API key management
Create, list, and revoke API keys programmatically.
HTTP endpoints on this page
- POST/api-keys
- GET/api-keys
- DELETE/api-keys/{api_key_id}
Parameters and response shapes for each are in the API reference.
You can manage API keys from the Dashboard or through the SDK on any tier. Each account can hold several active keys; give each one a purpose so a leaked key can be revoked without breaking the others.
Methods
api_keys.listYour active keys and their labels.anyapi_keys.createMint a new key — the only call that returns the key material.anyapi_keys.revokeInvalidate a key immediately.any
How keys work
The key is shown once. create() is the only call that ever returns the key material (api_key). Store it before the call returns, or mint another. Afterwards a key is known only by its api_key_id (the handle you pass to revoke()) and its key_prefix, the first characters such as pk_live_ab12, which let you tell keys apart without being able to reconstruct one.
Name keys by purpose: "notebook", "production", "CI pipeline". A blank name falls back to your account name.
Revocation is immediate: any request still using the key returns 401 Unauthorized. Revoked keys drop out of list(), and revoking an unknown or already revoked key is a 404. You can also revoke from the Dashboard with the delete button next to any key.
Examples
keys = client.api_keys.list()
for key in keys:
print(key["name"], key["key_prefix"], key["created_at"])Create a key, keep its material, and revoke it by id:
new_key = client.api_keys.create(name="Training script")
# Save this, it won't be shown again
print(new_key["api_key"][:12], "...")
client.api_keys.revoke(key_id=new_key["api_key_id"])