# API Keys

Source: https://docs.autessa.com/docs/api/poweruser/keys

> Poweruser endpoints for provisioning, scoping, sharing, rotating, and auditing client API keys that belong to you and never reach more than you can.

# API Keys

These endpoints let a poweruser credential create and manage <strong>client API keys</strong>: the scoped keys that call the client-side execution API (`/clients/…`). They mirror the Builder's <a href="/docs/guide/api-management/api-keys">API Management page</a> one-for-one. Every key belongs to the person who created it, is private to them unless shared, and can never reach more than they can.

> Only **client** keys are managed here. Poweruser keys (`pwrusr:…`), CLI keys, and the keys behind webhook handlers are created, rotated and revoked from the Builder only. Every request follows the same rules as the Builder: the caller becomes the owner of any key it creates, nothing a key is given may exceed the caller's own access, and a key's identity is always set by Autessa, never by the request.

---

## Base URL

```
https://api.autessa.com/autessa_poweruser/keys
```

All endpoints are `POST` with a JSON body. Authenticate with a poweruser key or temporary credential in the `Authorization` header (no `Bearer` prefix):

```
Authorization: pwrusr:{id}:{secret}
```

Key management isn't available to hosted apps: the key endpoints can't be added to an app's **allowedPoweruserEndpoints** (see [poweruser endpoint options](/docs/api/poweruser/custom-apps.md#list-poweruser-endpoint-options)). Call them with your own poweruser key.

### Who can do what

Every key in a response carries an `access` object describing what *you* may do with it, so a client can turn actions on or off without guessing.

| Action | Who |
|---|---|
| See the key (`/get`, `/all`, usage) | Its owner, anyone it is shared with, and company Admins |
| Narrow it (lower limits, remove resources or operations, disable) | Its owner, and people it is shared with at WRITE or ADMIN |
| Widen it, rotate it, share it | Its owner, or someone it is shared with at ADMIN who can reach everything the key can |
| Disable or delete it | Its owner, people it is shared with at ADMIN, and company Admins |
| Claim a legacy key | Company Admins who can reach everything the key can |

Keys are shared through the standard sharing endpoints with resource type `API_KEY` at `READ`, `WRITE`, or `ADMIN`. Sharing a key never reveals its secret.

---

## The API key object

- `id` (string) — Opaque id of the key — the prefix before the `:` in the secret value.
- `keyName` (string) — Display name shown in the key list.
- `keyDescription` (string) — What the key is used for.
- `allResources` (boolean) — When `true` the key may access every resource in the company and `permissions` is ignored.
- `permissions` (array<object>) — Per-resource-type grants: `{ resourceType: "TOOL" | "AGENT" | "MANAGER" | "AUTESSADB" | "CUSTOM_WEBHOOK" | "ESIGNATURE_ENVELOPE", resourceIds: string[] }`. An empty `resourceIds` acts as a wildcard for that type.
- `isEnabled` (boolean) — A disabled key authenticates to nothing.
- `rateLimitPerMinute` (integer) — Per-minute cap (default 60).
- `rateLimitPerDay` (integer) — Per-day cap (default 5000; must be ≥ `rateLimitPerMinute`).
- `allowedOrigins` (array<string>) — Optional CORS allowlist; empty means unrestricted.
- `metadata.autessaDbMetadata` (object) — `{ globalAllowedOperations: ["READ","WRITE","DELETE"], tablePermissions: { "<tableId>": ["READ","WRITE"] } }` — per-table operation overrides win over the global set. An absent/empty list means all operations are allowed.
- `identityMode` (string) — How the key acts: `ACT_AS_OWNER` (default) runs requests as the owner, narrowed to the key's scope; `SERVICE_ROLE` runs them as the key itself, limited to the AutessaDB roles in `serviceRoleIds` and never more than the owner can see. Keys with `allowedOrigins` must be `SERVICE_ROLE`.
- `serviceRoleIds` (array<string>) — For `SERVICE_ROLE` keys, the AutessaDB [roles](/docs/api/autessadb.md#row-and-column-security) assigned to the key. On a table where none of these roles applies, the key sees no rows. You can assign only roles on tables you administer.
- `ownerUserId` (string) — Read-only. The user who owns the key — whoever created it. Absent on legacy keys.
- `ownerName` (string) — Read-only. The owner's display name.
- `legacy` (boolean) — Read-only. `true` for a key created before keys had owners. Legacy keys keep working, are listed only for company Admins, and can be claimed with `/claim` (below).
- `access` (object) — Read-only. What the caller may do with this key: `canView`, `canEdit` (narrow), `canWiden`, `canRotate`, `canShare`, `canDisable`, `canDelete` (booleans), and `rotateBlockedReason` (string, present when `canRotate` is `false`).

```json title="Scoped key for an app's background scripts"
{
  "keyName": "support-internal-scripts",
  "keyDescription": "Used by the support desk's trigger and scheduled scripts.",
  "allResources": false,
  "isEnabled": true,
  "rateLimitPerMinute": 600,
  "rateLimitPerDay": 200000,
  "permissions": [
    { "resourceType": "AUTESSADB", "resourceIds": ["fQMiNu10sCdT", "6m3BMDOhub7D"] },
    { "resourceType": "TOOL", "resourceIds": ["DVb0iQNqSxOE"] }
  ],
  "metadata": {
    "autessaDbMetadata": {
      "globalAllowedOperations": ["READ"],
      "tablePermissions": { "fQMiNu10sCdT": ["READ", "WRITE"], "6m3BMDOhub7D": ["READ", "WRITE"] }
    }
  }
}
```

---

## Create Key **POST** `/create`

Mints a new client key and returns its secret **exactly once**. Every table, operation, tool, agent, and role you give the key is checked against your own access; a request that asks for more is refused with a message naming the resource.

### Request Body

- `apiKey` (object, required) — The desired configuration — see [The API key object](#the-api-key-object). The caller becomes the owner. `isSystemKey` and any identity settings in `metadata` (linked user, CLI, or app scoping) are ignored.

### Response

- `keyValue` (string) — The full secret, formatted `{keyId}:{secret}`. Store it now; it is never returned again.
- `apiKey` (object) — The stored configuration (without the secret).
- `errors` (array<string>) — Array of error messages. Absent on success.

```bash title="cURL"
curl https://api.autessa.com/autessa_poweruser/keys/create \
  -H "Authorization: $POWERUSER_KEY" \
  -H "Content-Type: application/json" \
  -d '{"apiKey": {"keyName": "support-internal-scripts", "allResources": false, "isEnabled": true}}'
```

```json title="JSON"
{
  "keyValue": "c1f2a3b4-5d6e-4789-9abc-0def12345678:Xk9…",
  "apiKey": { "id": "c1f2a3b4-5d6e-4789-9abc-0def12345678", "keyName": "support-internal-scripts", "isEnabled": true }
}
```

---

## Get Key **POST** `/get`

Fetches one key's configuration (never the secret). Keys outside your company, and keys you can't see, report as not found.

### Request Body

- `apiKeyId` (string, required) — Id of the key.

### Response

- `apiKey` (object) — See [The API key object](#the-api-key-object).

```bash title="cURL"
curl https://api.autessa.com/autessa_poweruser/keys/get \
  -H "Authorization: $POWERUSER_KEY" \
  -H "Content-Type: application/json" \
  -d '{"apiKeyId": "c1f2a3b4-5d6e-4789-9abc-0def12345678"}'
```

---

## List Keys **POST** `/all`

Lists client keys (secrets never included). Not paginated.

### Request Body

- `view` (string) — `MINE` (default): keys you own and keys shared with you. `ALL`: every key in the company, including legacy keys — company Admins only.

### Response

- `apiKeys` (array<object>) — The keys.

```bash title="cURL"
curl https://api.autessa.com/autessa_poweruser/keys/all \
  -H "Authorization: $POWERUSER_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'
```

---

## Update Key **POST** `/update`

Replaces the stored configuration wholesale — start from the entity returned by `/get`. Does not rotate the secret and does not itself grant per-resource permissions. The owner and the identity settings in `metadata` can't be changed here and are ignored. Someone the key is shared with at WRITE may only narrow it; widening it (more resources, operations, or roles, or higher limits) requires `access.canWiden`. Every grant is re-checked against both the owner's access and yours.

### Request Body

- `apiKeyId` (string, required) — Id of the key.
- `updatedApiKey` (object, required) — The complete desired configuration.

```bash title="cURL"
curl https://api.autessa.com/autessa_poweruser/keys/update \
  -H "Authorization: $POWERUSER_KEY" \
  -H "Content-Type: application/json" \
  -d '{"apiKeyId": "c1f2…", "updatedApiKey": {"id": "c1f2…", "keyName": "support-internal-scripts", "rateLimitPerMinute": 120, "isEnabled": true}}'
```

---

## Refresh Key **POST** `/refresh`

Rotates the secret. The previous secret stops working the moment this succeeds; the new value is returned once.

Only the owner, or someone the key is shared with at ADMIN who can reach everything the key can, may rotate it. Poweruser, CLI, webhook-handler, and system keys can't be rotated here. Otherwise the call returns `403` with "You can't rotate this key because it can reach data you can't."

### Request Body

- `apiKeyId` (string, required) — Id of the key.

### Response

- `keyValue` (string) — The new secret, `{keyId}:{secret}`.

```bash title="cURL"
curl https://api.autessa.com/autessa_poweruser/keys/refresh \
  -H "Authorization: $POWERUSER_KEY" \
  -H "Content-Type: application/json" \
  -d '{"apiKeyId": "c1f2a3b4-5d6e-4789-9abc-0def12345678"}'
```

---

## Enable / Disable Key **POST** `/enable · /disable`

`/disable` makes the key authenticate to nothing immediately (it is not deleted). `/enable` re-activates it with its existing secret.

### Request Body

- `apiKeyId` (string, required) — Id of the key.

```bash title="cURL"
curl https://api.autessa.com/autessa_poweruser/keys/disable \
  -H "Authorization: $POWERUSER_KEY" \
  -H "Content-Type: application/json" \
  -d '{"apiKeyId": "c1f2a3b4-5d6e-4789-9abc-0def12345678"}'
```

---

## Delete Key **POST** `/delete`

Permanently deletes a key. The key must already be disabled.

### Request Body

- `apiKeyId` (string, required) — Id of the key.

### Response

- `deleted` (boolean) — Whether the key was deleted.

```bash title="cURL"
curl https://api.autessa.com/autessa_poweruser/keys/delete \
  -H "Authorization: $POWERUSER_KEY" \
  -H "Content-Type: application/json" \
  -d '{"apiKeyId": "c1f2a3b4-5d6e-4789-9abc-0def12345678"}'
```

---

## Claim Legacy Key **POST** `/claim`

Makes the caller the owner of a legacy key (one with `legacy: true`) and turns it into an `ACT_AS_OWNER` key that follows every rule on this page. The secret doesn't change. Company Admins only, and only when the caller can reach everything the key can.

### Request Body

- `apiKeyId` (string, required) — Id of the legacy key.

### Response

- `apiKey` (object) — The claimed key, now with `ownerUserId` set and `legacy: false`.

```bash title="cURL"
curl https://api.autessa.com/autessa_poweruser/keys/claim \
  -H "Authorization: $POWERUSER_KEY" \
  -H "Content-Type: application/json" \
  -d '{"apiKeyId": "c1f2a3b4-5d6e-4789-9abc-0def12345678"}'
```

---

## Permissions **POST** `/permissions/…`

Adjust a key's scoped grants. All are no-ops on a key with `allResources = true`. Adding a grant requires `access.canWiden` and is checked against your access and the owner's; removing one requires `access.canEdit`.

| Path | Body | Effect |
|---|---|---|
| `/permissions/add-resource` | `{ apiKeyId, resourceType, resourceId }` | Grant one resource. |
| `/permissions/add-group` | `{ apiKeyId, permissions: { resourceType, resourceIds } }` | Grant a set of resources of one type. |
| `/permissions/delete-specific` | `{ apiKeyId, resourceType, resourceId }` | Revoke one resource grant. |
| `/permissions/set-all-for-type` | `{ apiKeyId, resourceType }` | Replace per-id grants with a wildcard for the type. |
| `/permissions/remove-all-for-type` | `{ apiKeyId, resourceType }` | Revoke every grant of the type. |

`resourceType` is one of `TOOL`, `AGENT`, `MANAGER`, `AUTESSADB`, `CUSTOM_WEBHOOK`, `ESIGNATURE_ENVELOPE`.

```bash title="cURL"
curl https://api.autessa.com/autessa_poweruser/keys/permissions/add-resource \
  -H "Authorization: $POWERUSER_KEY" \
  -H "Content-Type: application/json" \
  -d '{"apiKeyId": "c1f2…", "resourceType": "AUTESSADB", "resourceId": "fQMiNu10sCdT"}'
```

---

## Monthly Usage **POST** `/transactions/monthly-stats`

Aggregated request counts for a key in a given month, broken down by endpoint, agent, and tool.

### Request Body

- `apiKeyId` (string, required) — Id of the key.
- `year` (integer, required) — Four-digit year.
- `month` (integer, required) — Month (1–12).

```bash title="cURL"
curl https://api.autessa.com/autessa_poweruser/keys/transactions/monthly-stats \
  -H "Authorization: $POWERUSER_KEY" \
  -H "Content-Type: application/json" \
  -d '{"apiKeyId": "c1f2…", "year": 2026, "month": 8}'
```

---

## Errors

Refusals come back with HTTP `400` or `403` and a plain-language `message`:

| Message | Why |
|---|---|
| You can't give this key access to table “Orders” because you don't have WRITE access to it. | A grant asked for more than you or the key's owner hold. The same wording names tools, agents, and roles. |
| You can't rotate this key because it can reach data you can't. | You aren't the owner, and the key reaches tables, rows, tools, or agents you can't. |
| Keys used on websites (allowed origins) must use their own role, not act as you. | A key with `allowedOrigins` was saved as `ACT_AS_OWNER`. |

---

## Related

- [API Keys guide](/docs/guide/api-management/api-keys.md)
- [AutessaDB row and column security](/docs/api/autessadb.md#row-and-column-security)

