--- title: "Create an API key" canonical: "https://admiral.io/docs/api/users/ApiKeyAPI_CreateApiKey" --- # Create an API key `POST https://api.admiral.io/v1/users/{user}/apiKeys` - ALREADY_EXISTS when the caller already has an active, unexpired key with that name. - PERMISSION_DENIED when `parent` is not the caller. Scope: `apikey:write` ### Path parameters - `user` (string, required): The user id. ### Request body - `uid` (string): `key-` and twelve base36 characters. Never changes and is never reused, so it is what a reference to the key holds. Pattern `^key-[0-9a-z]+$`. Read-only. - `name` (string, required): (IMMUTABLE) The name, such as `ci-deploy`. Unique among the binding's keys that can still authenticate, set on create and changed only by RenameApiKey. Lowercase letters, digits and hyphens, starting with a letter and ending with a letter or digit, 1 to 63 characters. It may not have the shape of a uid (`key-` and twelve characters). name.not_uid // an API key name may not have the shape of a uid Pattern `^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$`. Length 1 to 63. - `display_name` (string): A label for people, such as "CI deploy". Optional; clients show the name when it is unset. Length at most 128. - `resource_name` (string): (IDENTIFIER) The resource name, such as `users/usr-01j9t5b6c3h1/apiKeys/ci-deploy`. Its parent says whose key it is. Built from the names of the key and its parent, so it changes when either is renamed; refer to a key by `uid` to keep a reference stable. Identifies the key on update. Pattern `^(users/(usr-[0-9a-z]+|-)|serviceAccounts/([a-z]([a-z0-9-]{0,61}[a-z0-9])?|-))/apiKeys/[a-z]([a-z0-9-]{0,61}[a-z0-9])?$`. - `scopes` (array of string): The scopes granted to this key, and the ceiling on any access token minted from it. Must be a subset of the caller's own scopes. Items at most 255. - `expires_at` (Timestamp): (IMMUTABLE) When the key expires. Unset never expires. Fixed at creation; organization policy may cap it. - `status` (ApiKeyStatus): ApiKeyStatus represents the lifecycle state of an API key. One of `API_KEY_STATUS_UNSPECIFIED`, `ACTIVE`, `REVOKED`. Read-only. - `last_used_at` (Timestamp): When the key was last exchanged for an access token. Minted tokens are reused for their lifetime, so this reads as "still in use" at that granularity, not as the time of the last request. Read-only. - `revoked_at` (Timestamp): Set when the key was revoked. Read-only. - `etag` (string): Changes whenever the key does. Send it back on update or rename to refuse the change if someone else changed the key first. Read-only. - `created_by` (ActorRef): ActorRef is a lightweight reference to the user or agent that performed an action. Server-populated on all resource responses. Clients should never send this. Read-only. - `id` (string): The actor's typed id: a `usr-` user id or an `sa-` service account id. - `display_name` (string): Human-readable name (e.g., "John Smith", "deploy-bot"). - `email` (string): Email address (empty for non-human actors). - `created_at` (Timestamp): A point in time in RFC 3339 format, with up to nanosecond precision. Output uses UTC (`Z`); input may use an offset from UTC. Read-only. ### Response 200 Success - `api_key` (ApiKey): The created key metadata. - `uid` (string): `key-` and twelve base36 characters. Never changes and is never reused, so it is what a reference to the key holds. Pattern `^key-[0-9a-z]+$`. Read-only. - `name` (string, required): (IMMUTABLE) The name, such as `ci-deploy`. Unique among the binding's keys that can still authenticate, set on create and changed only by RenameApiKey. Lowercase letters, digits and hyphens, starting with a letter and ending with a letter or digit, 1 to 63 characters. It may not have the shape of a uid (`key-` and twelve characters). name.not_uid // an API key name may not have the shape of a uid Pattern `^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$`. Length 1 to 63. - `display_name` (string): A label for people, such as "CI deploy". Optional; clients show the name when it is unset. Length at most 128. - `resource_name` (string): (IDENTIFIER) The resource name, such as `users/usr-01j9t5b6c3h1/apiKeys/ci-deploy`. Its parent says whose key it is. Built from the names of the key and its parent, so it changes when either is renamed; refer to a key by `uid` to keep a reference stable. Identifies the key on update. Pattern `^(users/(usr-[0-9a-z]+|-)|serviceAccounts/([a-z]([a-z0-9-]{0,61}[a-z0-9])?|-))/apiKeys/[a-z]([a-z0-9-]{0,61}[a-z0-9])?$`. - `scopes` (array of string): The scopes granted to this key, and the ceiling on any access token minted from it. Must be a subset of the caller's own scopes. Items at most 255. - `expires_at` (Timestamp): (IMMUTABLE) When the key expires. Unset never expires. Fixed at creation; organization policy may cap it. - `status` (ApiKeyStatus): ApiKeyStatus represents the lifecycle state of an API key. One of `API_KEY_STATUS_UNSPECIFIED`, `ACTIVE`, `REVOKED`. Read-only. - `last_used_at` (Timestamp): When the key was last exchanged for an access token. Minted tokens are reused for their lifetime, so this reads as "still in use" at that granularity, not as the time of the last request. Read-only. - `revoked_at` (Timestamp): Set when the key was revoked. Read-only. - `etag` (string): Changes whenever the key does. Send it back on update or rename to refuse the change if someone else changed the key first. Read-only. - `created_by` (ActorRef): ActorRef is a lightweight reference to the user or agent that performed an action. Server-populated on all resource responses. Clients should never send this. Read-only. - `id` (string): The actor's typed id: a `usr-` user id or an `sa-` service account id. - `display_name` (string): Human-readable name (e.g., "John Smith", "deploy-bot"). - `email` (string): Email address (empty for non-human actors). - `created_at` (Timestamp): A point in time in RFC 3339 format, with up to nanosecond precision. Output uses UTC (`Z`); input may use an offset from UTC. Read-only. - `secret` (string): The raw secret, shown exactly once and never again. It reads `admp__`: the key `key-8r3t6w1y4n9z` has a secret starting `admp_8r3t6w1y4n9z_`, so a secret found anywhere names its key.