unkey.py to call the Unkey API from Python. The current release is , and it needs Python 3.10 or newer. Every method has a regular and an _async version. Methods are grouped as unkey.keys, unkey.apis, unkey.identities, unkey.permissions, unkey.ratelimit, unkey.analytics, and unkey.portal.
You need a root key with the permissions listed on this page. Create one in the dashboard under Settings > Root Keys. See Permission reference for every permission.
Install
Construct the client
root_key is your root key. The client is a context manager that closes its connections on exit. In a long-running service, create one client and reuse it. To change retries, pass retry_config=RetryConfig(...) from unkey.py.utils to the client or to one call.
Verify a key
snake_case keyword arguments (tags, permissions, credits, ratelimits). An invalid key isn’t an exception: data.valid is false and data.code says why. See Verifying keys for what each check means and keys.verifyKey for the schema.
Create a key
byte_length, meta, roles, expires, credits, ratelimits, recoverable) are described in Creating keys, and the endpoint is keys.createKey.
Apply a rate limit
Handle errors
HTTP errors raise anerrors.UnkeyError, with message, status_code, headers, body, and raw_response. Each status has its own subclass with a typed data attribute holding the API’s meta and error fields.
BadRequestErrorResponse (400), UnauthorizedErrorResponse (401), ForbiddenErrorResponse (403), NotFoundErrorResponse (404), ConflictErrorResponse (409), GoneErrorResponse (410), PreconditionFailedErrorResponse (412), UnprocessableEntityErrorResponse (422), TooManyRequestsErrorResponse (429), InternalServerErrorResponse (500), and ServiceUnavailableErrorResponse (503). Network failures raise httpx.RequestError subclasses such as httpx.ConnectError and httpx.TimeoutException. Each endpoint page in the API reference, for example keys.getKey, lists which errors it can return.
Next steps
Creating keys
Every field a key can carry.
API reference
Request and response fields for every method.