# Change an API key

URL: https://heaven.dev/docs/reference/api-keys/edit
Updated: 2026-11-21

Change an active API key's permissions, label or expiration in place. Omitted settings retain their values. Supplying any resource scope replaces the entire scope. Named-command keys lack permission to edit API keys.

`POST /v1/account/api-key/modify`

## Parameters

- `key` (string, required): The key's ID (see `api-key view`).
- `label` (string): Replacement label for the key. Use one line of up to 200 bytes. Omit to keep the current label.
- `expires` (string): Replacement lifetime counted from now, from 1s through 365d, or `never`. Omit to retain the current expiration.
- `commands` (string[]): Command in the replacement permissions list, such as `restart`. Omit to keep the current commands.
- `no_scope` (boolean): Remove the key's resource scope. Use this option or provide replacement scope fields.
- `scope` (object): Resource scope by pool, Computer or tag. Any matching list grants access within your permissions; each list accepts up to 64 entries.
  - `computers` (string[]): Computer name or ID to include in the replacement scope. Providing any scope field replaces the full scope.
  - `pools` (string[]): Pool name or ID to include in the replacement scope along with its Computers. Providing any scope field replaces the full scope.
  - `tags` (string[]): Tag whose Computers to include in the replacement scope. Providing any scope field replaces the full scope.

## Returns

- `data` (object, always present): An API key's identity, permissions and lifetime.
  - `cmds` (string[] | null, always present): Permitted commands, subject to your permissions. `*` permits all commands for a sign-in key.
  - `computer_names` (map<string, string>): Names of the Computers its scope names, by ID, those its organization still has. May be omitted.
  - `created_at` (string (date-time), always present): When the key was created.
  - `expires_at` (string (date-time) | null, always present): When the key expires, or null if it has no expiry.
  - `id` (string, always present): Key ID for editing, rotation or revocation.
  - `label` (string, always present): User-assigned label.
  - `last_used_at` (string (date-time) | null, always present): Last recorded use, or null if no use has been recorded.
  - `organization` (string): Organization the key acts in. Sign-in keys can omit this to select an organization per request. May be omitted.
  - `previous_secret_expires_at` (string (date-time)): Expiry of the replaced secret, included while it remains accepted. May be omitted.
  - `revoked_at` (string (date-time) | null, always present): When the key was revoked, or null if it has not been revoked.
  - `rotated_at` (string (date-time) | null, always present): When its secret was last rotated, or null if it has not been rotated.
  - `scope` (object): Resource restrictions in addition to your permissions. An absent scope adds no restriction. May be omitted.
    - `computers` (string[]): Computer IDs included in the key's scope. May be omitted.
    - `pools` (string[]): Pool IDs included in the key's scope. May be omitted.
    - `tags` (string[]): Tags selecting Computers the key can reach. May be omitted.
  - `token` (string): Newly issued secret, returned only on creation or rotation. May be omitted.

## Errors

Each code is explained in full at https://heaven.dev/docs/reference/errors.

| Code | Status | What happened |
|---|---:|---|
| `invalid` | 400 | An input is missing or invalid. |
| `unauthenticated` | 401 | The credential is missing, invalid, expired or revoked. |
| `denied` | 403 | The caller lacks permission for this action. |
| `not_found` | 404 | The resource is absent or inaccessible to this caller. |
| `conflict` | 409 | The request conflicts with the current resource state or an earlier request. |
| `over_capacity` | 409 | The request exceeds a resource or credential allowance. |
| `access_list_full` | 409 | The change would exceed the access-list allowance. |
| `payment_required` | 402 | Payment or credit is required. |
| `rate_limited` | 429 | The caller's request rate exceeds its limit. |
| `busy` | 429 | Too much work is in progress to accept this request. |
| `unknown` | 503 | The outcome is unconfirmed; a change may have happened. |
| `unavailable` | 503 | The service or requested feature is unavailable. |

## Notes

- A key that expires cannot give a key a later expiry than its own, and CLI and MCP sign-ins last 90 days. Use management SSH or the dashboard for a longer expiry or `never`. CLI: `heaven login` with `HEAVEN_API_KEY` unset. MCP: Heaven sign-in. cURL: `HEAVEN_SIGN_IN_KEY` from approved device sign-in (`POST /v1/auth/create`).
- A key limited to a command list cannot run this command.

## Examples

```sh tab="heaven CLI"
heaven api-key edit KEY
  [--label LABEL]
  [--expires DURATION]
  [--command COMMAND ...]
  [--scope-pool SCOPE-POOL ...]
  [--scope-computer SCOPE-COMPUTER ...]
  [--scope-tag SCOPE-TAG ...]
  [--no-scope]
```

```sh tab="SSH"
ssh cli@heaven.dev api-key edit KEY
  [--label LABEL]
  [--expires DURATION]
  [--command COMMAND ...]
  [--scope-pool SCOPE-POOL ...]
  [--scope-computer SCOPE-COMPUTER ...]
  [--scope-tag SCOPE-TAG ...]
  [--no-scope]
```

```sh tab="cURL"
curl https://heaven.dev/v1/account/api-key/modify \
  -H "Authorization: Bearer $HEAVEN_SIGN_IN_KEY" \
  --json '{"action": "edit", "key": "5ad2f04d-1fdc-46c5-aa17-47acd11e5ca8", "expires": "7d", "commands": ["view", "restart"]}'
```

```json tab="MCP"
{ "tool": "api-key_edit",
  "arguments": { "key": "5ad2f04d-1fdc-46c5-aa17-47acd11e5ca8", "expires": "7d", "commands": ["view", "restart"] } }
```

Response:

```json title="Response excerpt"
{
  "version": 1,
  "data": {
    "cmds": [
      "view",
      "restart"
    ],
    "created_at": "2026-11-16T12:00:00Z",
    "expires_at": "2026-11-23T12:00:00Z",
    "id": "5ad2f04d-1fdc-46c5-aa17-47acd11e5ca8",
    "label": "deploy",
    "last_used_at": null,
    "organization": "acme",
    "revoked_at": null,
    "rotated_at": null
  }
}
```
