---
title: "Platform API: Keys"
description: "List keys, issue a key, rotate a key, update a publishable key, revoke a key, list workspace keys, issue a workspace key, rotate a workspace key, revoke a workspace key, or get the current workspace key, with the Agentpost API."
url: "https://agentpost.tools/docs/platform/reference/keys"
kind: reference
---

# Keys

A project’s keys. A secret key, `sk_test_…` for `dev` or `sk_live_…` for `prd`, is for your server: it is shown once and stored as a hash. A publishable key, `pk_test_…` or `pk_live_…`, is for a browser or a native app: it is public, works only from the origins it lists or, when it allows native apps, with no origin, and reaches only a service’s sign-in operations. The workspace’s owners get an email whenever a key is issued or rotated, or its origins or native allowance change. A workspace key, `wk_test_…` or `wk_live_…`, belongs to a workspace rather than a project: it reads every project of the workspace in its environment, within the permissions it was issued with, and is shown once, stored as a hash, and rotated like a secret key.

Paths are from `https://api.agentpost.tools`, and every route follows the [API basics](/docs/platform/api-basics.md). The examples send the first credential the route takes; [Credentials](/docs/platform/concepts/credentials.md) explains each one.

## List keys

`GET /v1/projects/{id}/keys`

Every key of the project, oldest first, revoked ones included. Never a secret key’s secret.

-   **Who may call:** A member of the workspace, with its API key; a member of the workspace, with its session; or a delegate, with its delegated token.
-   **Access:** The caller holds `apoa.key:view` in the project’s workspace.
-   **Credential:** the examples send your API key, `agp_ak_apoa_…`, as `Authorization: Bearer <token>`.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | A project ID, `prj_…`. The `id` of a [`Project`](/docs/platform/reference/projects.md#the-project-object). |

### Response

`200 OK`, with:

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `keys` | [`Key`](/docs/platform/reference/keys.md#the-key-object) array | Always |  |

### Errors

-   [`forbidden`](/docs/errors.md#forbidden) (403)
-   [`not_found`](/docs/errors.md#not_found) (404)

Any operation can also answer with the codes [Conventions](/docs/platform/reference.md#conventions) lists.

```bash tab="curl"
curl https://api.agentpost.tools/v1/projects/prj_01JDKYC5RZKAFFK3K2ENNC1ZTK/keys \
  -H "Authorization: Bearer agp_ak_apoa_…"
```

```json title="Response"
{
  "keys": [
    {
      "id": "key_01JDZ11YP80FXYTCSE1CE31KM0",
      "projectId": "prj_01JDKYC5RZKAFFK3K2ENNC1ZTK",
      "environment": "dev",
      "kind": "secret",
      "name": "server",
      "prefix": "sk_test_4f1c9a2e7b3d",
      "status": "active",
      "createdAt": "2026-11-13T09:30:00.000Z"
    },
    {
      "id": "key_01JDMK0FRK03N1Z9T2JSHY4BPP",
      "projectId": "prj_01JDKYC5RZKAFFK3K2ENNC1ZTK",
      "environment": "dev",
      "kind": "publishable",
      "name": "web",
      "prefix": "pk_test_8d2f6a1c0e9b",
      "key": "pk_test_8d2f6a1c0e9b",
      "allowedOrigins": ["http://localhost:5173", "https://app.example.com"],
      "allowNativeApps": false,
      "status": "active",
      "createdAt": "2026-11-13T09:30:00.000Z"
    }
  ]
}
```

## Issue a key

`POST /v1/projects/{id}/keys`

Issues a secret key, or a publishable key with the origins it works from and whether native apps may use it.

-   **Who may call:** A member of the workspace, with its API key; a member of the workspace, with its session; or a delegate, with its delegated token.
-   **Access:** The caller holds `apoa.key:issue` in the project’s workspace.
-   **Credential:** the examples send your API key, `agp_ak_apoa_…`, as `Authorization: Bearer <token>`.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | A project ID, `prj_…`. The `id` of a [`Project`](/docs/platform/reference/projects.md#the-project-object). |

### Body

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | `string` | Yes | What it is for, such as `render`. |
| `environment` | `"dev"` or `"prd"` | Yes | `dev` for development and tests, `prd` for production. |
| `kind` | `string` | No | Default `"secret"`. One of `"secret"` or `"publishable"`. |
| `allowedOrigins` | `string[]` | No | A publishable key only: each origin as a browser sends it, such as `https://app.example.com`. No path or wildcard. `http` works only on `localhost`, `127.0.0.1`, or `[::1]`, for a `dev` key. Required, with 1 to 20 origins, unless the key allows native apps, when it may be left out or empty; up to 20 items. |
| `allowNativeApps` | `boolean` | No | A publishable key only: `true` lets a native app, such as an iOS, Android, or Expo app, use the key with no `Origin` header. A request that sends an `Origin` is still held to `allowedOrigins`; default `false`. |

### Response

`201 Created`, with:

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `key` | `string` | Always | The key itself. A secret key is shown once. |
| `record` | [`Key`](/docs/platform/reference/keys.md#the-key-object) | Always |  |

### Errors

-   [`forbidden`](/docs/errors.md#forbidden) (403)
-   [`not_found`](/docs/errors.md#not_found) (404)

Any operation can also answer with the codes [Conventions](/docs/platform/reference.md#conventions) lists.

```bash tab="curl"
curl -X POST https://api.agentpost.tools/v1/projects/prj_01JDKYC5RZKAFFK3K2ENNC1ZTK/keys \
  -H "Authorization: Bearer agp_ak_apoa_…" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "server",
    "environment": "dev"
  }'
```

```json title="Response"
{
  "key": "sk_test_…",
  "record": {
    "id": "key_01JDZ11YP80FXYTCSE1CE31KM0",
    "projectId": "prj_01JDKYC5RZKAFFK3K2ENNC1ZTK",
    "environment": "dev",
    "kind": "secret",
    "name": "server",
    "prefix": "sk_test_4f1c9a2e7b3d",
    "status": "active",
    "createdAt": "2026-11-13T09:30:00.000Z"
  }
}
```

## Rotate a key

`POST /v1/projects/{id}/keys/{keyId}/rotate`

Replaces a secret key with a new one of the same name and environment. Set `grace` to say how long the old key keeps working. The answer gives its `graceEndsAt` in `previous`. A grace of `0s` stops the old key at once and needs the key’s name as confirmation. To replace a publishable key, issue a new one and revoke the old one.

-   **Who may call:** A member of the workspace, with its API key; a member of the workspace, with its session; or a delegate, with its delegated token.
-   **Access:** The caller holds `apoa.key:rotate` in the project’s workspace.
-   **Credential:** the examples send your API key, `agp_ak_apoa_…`, as `Authorization: Bearer <token>`.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | A project ID, `prj_…`. The `id` of a [`Project`](/docs/platform/reference/projects.md#the-project-object). |
| `keyId` | `string` | Yes | A key ID, `key_…`. The `id` of a [`Key`](/docs/platform/reference/keys.md#the-key-object). |

### Body

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `grace` | `string` | Yes | A duration from `0s` to `7d`. |
| `confirm` | `string` | No | The key’s name, required when `grace` is `0s`. |

### Response

`201 Created`, with:

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `key` | `string` | Always | The new key. Shown once. |
| `record` | [`Key`](/docs/platform/reference/keys.md#the-key-object) | Always |  |
| `previous` | [`Key`](/docs/platform/reference/keys.md#the-key-object) | Always |  |

### Errors

-   [`confirmation_required`](/docs/errors.md#confirmation_required) (400)
-   [`conflict`](/docs/errors.md#conflict) (409)
-   [`forbidden`](/docs/errors.md#forbidden) (403)
-   [`not_found`](/docs/errors.md#not_found) (404)

Any operation can also answer with the codes [Conventions](/docs/platform/reference.md#conventions) lists.

```bash tab="curl"
curl -X POST https://api.agentpost.tools/v1/projects/prj_01JDKYC5RZKAFFK3K2ENNC1ZTK/keys/key_01JDZ11YP80FXYTCSE1CE31KM0/rotate \
  -H "Authorization: Bearer agp_ak_apoa_…" \
  -H "Content-Type: application/json" \
  -d '{
    "grace": "1h"
  }'
```

```json title="Response"
{
  "key": "sk_test_…",
  "record": {
    "id": "key_01JDZ6AJ7K56PD5A8JS97ZWT3G",
    "projectId": "prj_01JDKYC5RZKAFFK3K2ENNC1ZTK",
    "environment": "dev",
    "kind": "secret",
    "name": "server",
    "prefix": "sk_test_9b7e2d4c1a6f",
    "status": "active",
    "createdAt": "2026-11-13T09:30:00.000Z",
    "rotatedFrom": "key_01JDZ11YP80FXYTCSE1CE31KM0"
  },
  "previous": {
    "id": "key_01JDZ11YP80FXYTCSE1CE31KM0",
    "projectId": "prj_01JDKYC5RZKAFFK3K2ENNC1ZTK",
    "environment": "dev",
    "kind": "secret",
    "name": "server",
    "prefix": "sk_test_4f1c9a2e7b3d",
    "status": "grace",
    "createdAt": "2026-11-13T09:30:00.000Z",
    "graceEndsAt": "2026-11-13T10:30:00.000Z",
    "replacedBy": "key_01JDZ6AJ7K56PD5A8JS97ZWT3G"
  }
}
```

## Update a publishable key

`PATCH /v1/projects/{id}/keys/{keyId}`

Changes who may use a publishable key: its allowed origins, whether native apps may use it, or both. A field left out keeps its value, and the key must still allow an origin or native apps. The change takes effect on the next request, so the site or app the key is built into needs no new release.

-   **Who may call:** A member of the workspace, with its API key; a member of the workspace, with its session; or a delegate, with its delegated token.
-   **Access:** The caller holds `apoa.key:issue` in the project’s workspace.
-   **Credential:** the examples send your API key, `agp_ak_apoa_…`, as `Authorization: Bearer <token>`.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | A project ID, `prj_…`. The `id` of a [`Project`](/docs/platform/reference/projects.md#the-project-object). |
| `keyId` | `string` | Yes | A key ID, `key_…`. The `id` of a [`Key`](/docs/platform/reference/keys.md#the-key-object). |

### Body

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `allowedOrigins` | `string[]` | No | The whole new list. Empty only for a key that allows native apps; up to 20 items. |
| `allowNativeApps` | `boolean` | No | Whether a native app, which sends no `Origin`, may use the key. |

### Response

`200 OK`, with:

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `record` | [`Key`](/docs/platform/reference/keys.md#the-key-object) | Always |  |

### Errors

-   [`conflict`](/docs/errors.md#conflict) (409)
-   [`forbidden`](/docs/errors.md#forbidden) (403)
-   [`not_found`](/docs/errors.md#not_found) (404)

Any operation can also answer with the codes [Conventions](/docs/platform/reference.md#conventions) lists.

```bash tab="curl"
curl -X PATCH https://api.agentpost.tools/v1/projects/prj_01JDKYC5RZKAFFK3K2ENNC1ZTK/keys/key_01JDMK0FRK03N1Z9T2JSHY4BPP \
  -H "Authorization: Bearer agp_ak_apoa_…" \
  -H "Content-Type: application/json" \
  -d '{
    "allowedOrigins": [
      "https://app.example.com"
    ],
    "allowNativeApps": true
  }'
```

```json title="Response"
{
  "record": {
    "id": "key_01JDMK0FRK03N1Z9T2JSHY4BPP",
    "projectId": "prj_01JDKYC5RZKAFFK3K2ENNC1ZTK",
    "environment": "dev",
    "kind": "publishable",
    "name": "web",
    "prefix": "pk_test_8d2f6a1c0e9b",
    "key": "pk_test_8d2f6a1c0e9b",
    "allowedOrigins": ["https://app.example.com"],
    "allowNativeApps": true,
    "status": "active",
    "createdAt": "2026-11-13T09:30:00.000Z"
  }
}
```

## Revoke a key

`DELETE /v1/projects/{id}/keys/{keyId}`

Revokes a key at once. Every request with it fails from then on, and so do user tokens it minted.

-   **Who may call:** A member of the workspace, with its API key; a member of the workspace, with its session; or a delegate, with its delegated token.
-   **Access:** The caller holds `apoa.key:revoke` in the project’s workspace.
-   **Credential:** the examples send your API key, `agp_ak_apoa_…`, as `Authorization: Bearer <token>`.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | A project ID, `prj_…`. The `id` of a [`Project`](/docs/platform/reference/projects.md#the-project-object). |
| `keyId` | `string` | Yes | A key ID, `key_…`. The `id` of a [`Key`](/docs/platform/reference/keys.md#the-key-object). |

### Response

`200 OK`, with:

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `record` | [`Key`](/docs/platform/reference/keys.md#the-key-object) | Always |  |

### Errors

-   [`forbidden`](/docs/errors.md#forbidden) (403)
-   [`not_found`](/docs/errors.md#not_found) (404)

Any operation can also answer with the codes [Conventions](/docs/platform/reference.md#conventions) lists.

```bash tab="curl"
curl -X DELETE https://api.agentpost.tools/v1/projects/prj_01JDKYC5RZKAFFK3K2ENNC1ZTK/keys/key_01JDZ11YP80FXYTCSE1CE31KM0 \
  -H "Authorization: Bearer agp_ak_apoa_…"
```

```json title="Response"
{
  "record": {
    "id": "key_01JDZ11YP80FXYTCSE1CE31KM0",
    "projectId": "prj_01JDKYC5RZKAFFK3K2ENNC1ZTK",
    "environment": "dev",
    "kind": "secret",
    "name": "server",
    "prefix": "sk_test_4f1c9a2e7b3d",
    "status": "revoked",
    "createdAt": "2026-11-13T09:30:00.000Z",
    "revokedAt": "2026-11-13T09:30:00.000Z"
  }
}
```

## List workspace keys

`GET /v1/workspaces/{workspaceId}/keys`

Every key of the workspace, in both environments, oldest first, revoked ones included. Never a secret.

-   **Who may call:** A member of the workspace, with its API key; a member of the workspace, with its session; or a delegate, with its delegated token.
-   **Access:** The caller holds `apoa.workspace_key:view` in the workspace. A workspace the caller has no part in is not found.
-   **Credential:** the examples send your API key, `agp_ak_apoa_…`, as `Authorization: Bearer <token>`.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `workspaceId` | `string` | Yes | A workspace ID, `wsp_…`. It is `workspace.id` in the answer to [Sign up](/docs/platform/reference/workspaces.md#sign-up). |

### Response

`200 OK`, with:

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `keys` | [`WorkspaceKey`](/docs/platform/reference/keys.md#the-workspacekey-object) array | Always |  |

### Errors

-   [`forbidden`](/docs/errors.md#forbidden) (403)
-   [`not_found`](/docs/errors.md#not_found) (404)

Any operation can also answer with the codes [Conventions](/docs/platform/reference.md#conventions) lists.

```bash tab="curl"
curl https://api.agentpost.tools/v1/workspaces/wsp_01JDGKQN2K4RF0M0Z2HBASFA62/keys \
  -H "Authorization: Bearer agp_ak_apoa_…"
```

```json title="Response"
{
  "keys": [
    {
      "id": "wkey_01JDZ8M3Q4R5S6T7V8W9X0Y1Z2",
      "workspaceId": "wsp_01JDGKQN2K4RF0M0Z2HBASFA62",
      "environment": "prd",
      "name": "analytics",
      "permissions": ["events:read"],
      "prefix": "wk_live_3c8e1f5a9d27",
      "status": "active",
      "createdAt": "2026-11-13T09:30:00.000Z",
      "lastUsedAt": "2026-11-13T09:30:00.000Z"
    }
  ]
}
```

## Issue a workspace key

`POST /v1/workspaces/{workspaceId}/keys`

Issues a workspace key, which reads every project of the workspace in one environment, those added later included, within its permissions. Its permissions are fixed when it is issued; to change them, issue another key. The workspace’s owners get an email.

-   **Who may call:** A member of the workspace, with its API key; a member of the workspace, with its session; or a delegate, with its delegated token.
-   **Access:** The caller holds `apoa.workspace_key:issue` in the workspace. A workspace the caller has no part in is not found.
-   **Credential:** the examples send your API key, `agp_ak_apoa_…`, as `Authorization: Bearer <token>`.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `workspaceId` | `string` | Yes | A workspace ID, `wsp_…`. It is `workspace.id` in the answer to [Sign up](/docs/platform/reference/workspaces.md#sign-up). |

### Body

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | `string` | Yes | What it is for, such as `analytics`. |
| `environment` | `"dev"` or `"prd"` | Yes | `dev` for development and tests, `prd` for production. |
| `permissions` | `"events:read"[]` | Yes | What the key may do, one or more; at least 1. |
| `expiresAt` | `string` | No | When the key stops working, after now. Left out, it works until it is revoked. |

### Response

`201 Created`, with:

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `key` | `string` | Always | The key itself. Shown once. |
| `record` | [`WorkspaceKey`](/docs/platform/reference/keys.md#the-workspacekey-object) | Always |  |

### Errors

-   [`forbidden`](/docs/errors.md#forbidden) (403)
-   [`not_found`](/docs/errors.md#not_found) (404)

Any operation can also answer with the codes [Conventions](/docs/platform/reference.md#conventions) lists.

```bash tab="curl"
curl -X POST https://api.agentpost.tools/v1/workspaces/wsp_01JDGKQN2K4RF0M0Z2HBASFA62/keys \
  -H "Authorization: Bearer agp_ak_apoa_…" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "analytics",
    "environment": "prd",
    "permissions": [
      "events:read"
    ]
  }'
```

```json title="Response"
{
  "key": "wk_live_…",
  "record": {
    "id": "wkey_01JDZ8M3Q4R5S6T7V8W9X0Y1Z2",
    "workspaceId": "wsp_01JDGKQN2K4RF0M0Z2HBASFA62",
    "environment": "prd",
    "name": "analytics",
    "permissions": ["events:read"],
    "prefix": "wk_live_3c8e1f5a9d27",
    "status": "active",
    "createdAt": "2026-11-13T09:30:00.000Z"
  }
}
```

## Rotate a workspace key

`POST /v1/workspaces/{workspaceId}/keys/{workspaceKeyId}/rotate`

Replaces a workspace key with a new one of the same name, environment, permissions, and `expiresAt`. Set `grace` to say how long the old key keeps working. The answer gives its `graceEndsAt` in `previous`. A grace of `0s` stops the old key at once and needs the key’s name as confirmation.

-   **Who may call:** A member of the workspace, with its API key; a member of the workspace, with its session; or a delegate, with its delegated token.
-   **Access:** The caller holds `apoa.workspace_key:rotate` in the workspace. A workspace the caller has no part in is not found.
-   **Credential:** the examples send your API key, `agp_ak_apoa_…`, as `Authorization: Bearer <token>`.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `workspaceId` | `string` | Yes | A workspace ID, `wsp_…`. It is `workspace.id` in the answer to [Sign up](/docs/platform/reference/workspaces.md#sign-up). |
| `workspaceKeyId` | `string` | Yes | A workspace key ID, `wkey_…`. The `id` of a [`WorkspaceKey`](/docs/platform/reference/keys.md#the-workspacekey-object). |

### Body

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `grace` | `string` | Yes | A duration from `0s` to `7d`. |
| `confirm` | `string` | No | The key’s name, required when `grace` is `0s`. |

### Response

`201 Created`, with:

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `key` | `string` | Always | The new key. Shown once. |
| `record` | [`WorkspaceKey`](/docs/platform/reference/keys.md#the-workspacekey-object) | Always |  |
| `previous` | [`WorkspaceKey`](/docs/platform/reference/keys.md#the-workspacekey-object) | Always |  |

### Errors

-   [`confirmation_required`](/docs/errors.md#confirmation_required) (400)
-   [`conflict`](/docs/errors.md#conflict) (409)
-   [`forbidden`](/docs/errors.md#forbidden) (403)
-   [`not_found`](/docs/errors.md#not_found) (404)

Any operation can also answer with the codes [Conventions](/docs/platform/reference.md#conventions) lists.

```bash tab="curl"
curl -X POST https://api.agentpost.tools/v1/workspaces/wsp_01JDGKQN2K4RF0M0Z2HBASFA62/keys/wkey_01JDZ8M3Q4R5S6T7V8W9X0Y1Z2/rotate \
  -H "Authorization: Bearer agp_ak_apoa_…" \
  -H "Content-Type: application/json" \
  -d '{
    "grace": "1h"
  }'
```

```json title="Response"
{
  "key": "wk_live_…",
  "record": {
    "id": "wkey_01JDZ9N4R5S6T7V8W9X0Y1Z2A3",
    "workspaceId": "wsp_01JDGKQN2K4RF0M0Z2HBASFA62",
    "environment": "prd",
    "name": "analytics",
    "permissions": ["events:read"],
    "prefix": "wk_live_7a2d9e4b1c6f",
    "status": "active",
    "createdAt": "2026-11-13T09:30:00.000Z",
    "rotatedFrom": "wkey_01JDZ8M3Q4R5S6T7V8W9X0Y1Z2"
  },
  "previous": {
    "id": "wkey_01JDZ8M3Q4R5S6T7V8W9X0Y1Z2",
    "workspaceId": "wsp_01JDGKQN2K4RF0M0Z2HBASFA62",
    "environment": "prd",
    "name": "analytics",
    "permissions": ["events:read"],
    "prefix": "wk_live_3c8e1f5a9d27",
    "status": "grace",
    "createdAt": "2026-11-13T09:30:00.000Z",
    "lastUsedAt": "2026-11-13T09:30:00.000Z",
    "graceEndsAt": "2026-11-13T10:30:00.000Z",
    "replacedBy": "wkey_01JDZ9N4R5S6T7V8W9X0Y1Z2A3"
  }
}
```

## Revoke a workspace key

`DELETE /v1/workspaces/{workspaceId}/keys/{workspaceKeyId}`

Revokes a workspace key at once. Every new request with it fails from then on, and a live tail it opened stops within two heartbeats, 30 seconds by default. A revoked key can’t be restored.

-   **Who may call:** A member of the workspace, with its API key; a member of the workspace, with its session; or a delegate, with its delegated token.
-   **Access:** The caller holds `apoa.workspace_key:revoke` in the workspace. A workspace the caller has no part in is not found.
-   **Credential:** the examples send your API key, `agp_ak_apoa_…`, as `Authorization: Bearer <token>`.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `workspaceId` | `string` | Yes | A workspace ID, `wsp_…`. It is `workspace.id` in the answer to [Sign up](/docs/platform/reference/workspaces.md#sign-up). |
| `workspaceKeyId` | `string` | Yes | A workspace key ID, `wkey_…`. The `id` of a [`WorkspaceKey`](/docs/platform/reference/keys.md#the-workspacekey-object). |

### Response

`200 OK`, with:

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `record` | [`WorkspaceKey`](/docs/platform/reference/keys.md#the-workspacekey-object) | Always |  |

### Errors

-   [`forbidden`](/docs/errors.md#forbidden) (403)
-   [`not_found`](/docs/errors.md#not_found) (404)

Any operation can also answer with the codes [Conventions](/docs/platform/reference.md#conventions) lists.

```bash tab="curl"
curl -X DELETE https://api.agentpost.tools/v1/workspaces/wsp_01JDGKQN2K4RF0M0Z2HBASFA62/keys/wkey_01JDZ8M3Q4R5S6T7V8W9X0Y1Z2 \
  -H "Authorization: Bearer agp_ak_apoa_…"
```

```json title="Response"
{
  "record": {
    "id": "wkey_01JDZ8M3Q4R5S6T7V8W9X0Y1Z2",
    "workspaceId": "wsp_01JDGKQN2K4RF0M0Z2HBASFA62",
    "environment": "prd",
    "name": "analytics",
    "permissions": ["events:read"],
    "prefix": "wk_live_3c8e1f5a9d27",
    "status": "revoked",
    "createdAt": "2026-11-13T09:30:00.000Z",
    "lastUsedAt": "2026-11-13T09:30:00.000Z",
    "revokedAt": "2026-11-13T09:30:00.000Z"
  }
}
```

## Get the current workspace key

`GET /v1/workspace-keys/current`

What a workspace key reaches now: the key, and its workspace’s projects that it can read, those added after it was issued included. Name one of them in the `x-agentpost-project` header of each request the key makes to a service, such as `GET /v1/events/events`.

-   **Who may call:** A workspace key.
-   **Access:** The workspace key itself, `wk_test_…` or `wk_live_…`. Any other credential is refused.
-   **Credential:** the examples send a `dev` workspace key, `wk_test_…`, as `Authorization: Bearer <token>`.

### Response

`200 OK`, with:

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `key` | `object` | Always |  |
| `key.id` | `string` | Always | A workspace key ID, `wkey_…`. |
| `key.name` | `string` | Always |  |
| `key.workspaceId` | `string` | Always |  |
| `key.environment` | `"dev"` or `"prd"` | Always | `dev` for development and tests, `prd` for production. |
| `key.permissions` | `"events:read"[]` | Always |  |
| `key.status` | `string` | Always | Only keys with an `active` or `grace` status work. After rotation, the old key has `grace` until `graceEndsAt`, or until `expiresAt` if it comes first. A key becomes `expired` at either deadline. One of `"active"`, `"grace"`, `"expired"`, or `"revoked"`. |
| `key.graceEndsAt` | `string` | When set | After a rotation: when this key stops working. |
| `key.expiresAt` | `string` | When set | When it stops working, if it was issued to expire. |
| `projects` | `object[]` | Always | The workspace’s projects, oldest first, that aren’t deleted and adopted a service the key’s permissions read, as of this call. |
| `projects[].id` | `string` | Always | A project ID, `prj_…`. |
| `projects[].name` | `string` | Always |  |

### Errors

-   [`forbidden`](/docs/errors.md#forbidden) (403)

Any operation can also answer with the codes [Conventions](/docs/platform/reference.md#conventions) lists.

```bash tab="curl"
curl https://api.agentpost.tools/v1/workspace-keys/current \
  -H "Authorization: Bearer wk_test_…"
```

```json title="Response"
{
  "key": {
    "id": "wkey_01JDZ8M3Q4R5S6T7V8W9X0Y1Z2",
    "name": "analytics",
    "workspaceId": "wsp_01JDGKQN2K4RF0M0Z2HBASFA62",
    "environment": "prd",
    "permissions": ["events:read"],
    "status": "active"
  },
  "projects": [
    {
      "id": "prj_01JE2T7WQ8M4X6B1C9D3F5G7H0",
      "name": "Support desk"
    }
  ]
}
```

## The Key object

A key as a list shows it: never a secret key’s secret.

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `id` | `string` | Always | A key ID, `key_…`. |
| `projectId` | `string` | Always |  |
| `environment` | `"dev"` or `"prd"` | Always | `dev` for development and tests, `prd` for production. |
| `kind` | `string` | Always | One of `"secret"` or `"publishable"`. |
| `name` | `string` | Always | What the key is for, such as `render`. |
| `prefix` | `string` | Always | The key without its secret, to tell keys apart. A publishable key’s prefix is the whole key. |
| `key` | `string` | When set | A publishable key in full, since it is public. |
| `allowedOrigins` | `string[]` | When set | Where a publishable key works from in a browser. Empty only for a key that allows native apps. |
| `allowNativeApps` | `boolean` | When set | A publishable key only: `true` when a native app, which sends no `Origin`, may use it. |
| `status` | `string` | Always | Only keys with an `active` or `grace` status work. After rotation, the old key has `grace` until `graceEndsAt`, then `expired`. One of `"active"`, `"grace"`, `"expired"`, or `"revoked"`. |
| `createdAt` | `string` | Always | An ISO 8601 date and time. |
| `revokedAt` | `string` | When set | An ISO 8601 date and time. |
| `graceEndsAt` | `string` | When set | After a rotation: when this key stops working. |
| `rotatedFrom` | `string` | When set | The key this one replaced. |
| `replacedBy` | `string` | When set | The key that replaced this one. |

```json title="The Key object"
{
  "id": "key_01JDZ11YP80FXYTCSE1CE31KM0",
  "projectId": "prj_01JDKYC5RZKAFFK3K2ENNC1ZTK",
  "environment": "dev",
  "kind": "secret",
  "name": "server",
  "prefix": "sk_test_4f1c9a2e7b3d",
  "status": "active",
  "createdAt": "2026-11-13T09:30:00.000Z"
}
```

## The WorkspaceKey object

A workspace key as a list shows it: never its secret. It reads every project of its workspace in its environment, within its permissions.

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `id` | `string` | Always | A workspace key ID, `wkey_…`. |
| `workspaceId` | `string` | Always |  |
| `environment` | `"dev"` or `"prd"` | Always | `dev` for development and tests, `prd` for production. |
| `name` | `string` | Always | What the key is for, such as `analytics`. |
| `permissions` | `"events:read"[]` | Always | What the key may do, fixed when it is issued. `events:read`: Reads each project’s events and event types: query, lookup, one event, the live tail, and the type registry; at least 1. |
| `prefix` | `string` | Always | The key without its secret, `wk_test_…` or `wk_live_…`, to tell keys apart. |
| `status` | `string` | Always | Only keys with an `active` or `grace` status work. After rotation, the old key has `grace` until `graceEndsAt`, or until `expiresAt` if it comes first. A key becomes `expired` at either deadline. One of `"active"`, `"grace"`, `"expired"`, or `"revoked"`. |
| `createdAt` | `string` | Always | An ISO 8601 date and time. |
| `expiresAt` | `string` | When set | When it stops working, if it was issued to expire. |
| `lastUsedAt` | `string` | When set | When it last made a request. Written at most once an hour, so it can be up to an hour behind. Absent until its first request. |
| `revokedAt` | `string` | When set | An ISO 8601 date and time. |
| `graceEndsAt` | `string` | When set | After a rotation: when this key stops working. |
| `rotatedFrom` | `string` | When set | The key this one replaced. |
| `replacedBy` | `string` | When set | The key that replaced this one. |

```json title="The WorkspaceKey object"
{
  "id": "wkey_01JDZ8M3Q4R5S6T7V8W9X0Y1Z2",
  "workspaceId": "wsp_01JDGKQN2K4RF0M0Z2HBASFA62",
  "environment": "prd",
  "name": "analytics",
  "permissions": ["events:read"],
  "prefix": "wk_live_3c8e1f5a9d27",
  "status": "active",
  "createdAt": "2026-11-13T09:30:00.000Z",
  "lastUsedAt": "2026-11-13T09:30:00.000Z"
}
```
