API keys
A signed-in principal’s own credential. A key may be restricted to workspaces and permissions, which caps what it can do.
Principals explains which principals hold API keys, and Access checks how a key’s restrictions cap it.
Paths are relative to https://api.agentpost.tools/v1/identity, and every request follows the API basics. Who may call explains each kind of caller.
Create an API key
POST /principals/:id/api-keys
Issues an API key. The token is in the response once.
- Who may call: Your server or a signed-in principal.
- Access: Only the principal or your server.
- Credential: the examples send your project’s
devsecret key,sk_test_…, asAuthorization: Bearer <token>. - SDK:
client.apiKeys.create(principalId, input) - Idempotency-Key: optional. Retrying a write has the rule.
Path parameters
| Name | Type | Required | Description |
|---|---|---|---|
id |
string |
Yes | A principal ID, prn_…. The id of a Principal. |
Body
| Name | Type | Required | Description |
|---|---|---|---|
name |
string |
Yes | 1–120 characters. |
restrictions |
object |
No | |
restrictions. |
string[] |
No | At least 1. |
restrictions. |
string[] |
No | At least 1. |
expiresAt |
string |
No | An ISO 8601 date and time. |
Response
201 Created, with ApiKeyCreated.
Errors
Any operation can also answer with the codes Conventions lists.
List API keys
GET /principals/:id/api-keys
A principal’s keys, without their secrets.
- Who may call: Your server or a signed-in principal.
- Access: Only the principal or your server.
- Credential: the examples send your project’s
devsecret key,sk_test_…, asAuthorization: Bearer <token>. - SDK:
client.apiKeys.list(principalId)
Path parameters
| Name | Type | Required | Description |
|---|---|---|---|
id |
string |
Yes | A principal ID, prn_…. The id of a Principal. |
Response
200 OK, with:
| Name | Type | Present | Description |
|---|---|---|---|
apiKeys |
ApiKey array |
Always |
Errors
Any operation can also answer with the codes Conventions lists.
Rotate an API key
POST /api-keys/:id/rotate
Issues a replacement key. Set grace from 0s to 7d to choose how long the old key keeps working. 0s stops it at once. A key is replaced once: rotating a key already rotated answers conflict.
- Who may call: Your server or a signed-in principal.
- Access: Only the principal or your server.
- Credential: the examples send your project’s
devsecret key,sk_test_…, asAuthorization: Bearer <token>. - SDK:
client.apiKeys.rotate(id, input) - Idempotency-Key: optional. Retrying a write has the rule.
Path parameters
| Name | Type | Required | Description |
|---|---|---|---|
id |
string |
Yes | An API key ID, key_…. The id of a ApiKey. |
Body
| Name | Type | Required | Description |
|---|---|---|---|
grace |
string |
Yes | How long the old key keeps working, from 0s to 7d. Send 0s to stop it at once. |
Response
201 Created, with ApiKeyCreated.
Errors
Any operation can also answer with the codes Conventions lists.
Revoke an API key
DELETE /api-keys/:id
Revokes a key at once when the principal has another way to sign in.
- Who may call: Your server or a signed-in principal.
- Access: Only the principal or your server.
- Credential: the examples send your project’s
devsecret key,sk_test_…, asAuthorization: Bearer <token>. - SDK:
client.apiKeys.revoke(id) - Idempotency-Key: optional. Retrying a write has the rule.
Path parameters
| Name | Type | Required | Description |
|---|---|---|---|
id |
string |
Yes | An API key ID, key_…. The id of a ApiKey. |
Response
204 No Content, with no body.
Errors
conflict(409)forbidden(403)last_sign_in_method(409)not_found(404)
Any operation can also answer with the codes Conventions lists.
The ApiKeyCreated object
| Name | Type | Present | Description |
|---|---|---|---|
apiKey |
ApiKey |
Always | |
token |
string |
Always | The bearer token. Shown once. |
The ApiKey object
An API key as the API shows it: never with its secret or hash. prefix is the public part a holder sees on its copy.
| Name | Type | Present | Description |
|---|---|---|---|
id |
string |
Always | An API key ID, key_…. |
principalId |
string |
Always | A principal ID, prn_…. |
name |
string |
Always | |
prefix |
string |
Always | |
restrictions |
object |
When set | |
restrictions. |
string[] |
When set | |
restrictions. |
string[] |
When set | |
status |
"active" or "revoked" |
Always | |
expiresAt |
string |
When set | An ISO 8601 date and time. |
lastUsedAt |
string |
When set | An ISO 8601 date and time. |
createdAt |
string |
Always | An ISO 8601 date and time. |
createdBy |
string |
Always | A principal ID, prn_…, or "trusted_caller". |
revokedAt |
string |
When set | An ISO 8601 date and time. |
revokedBy |
string |
When set | A principal ID, prn_…, or "trusted_caller". |
rotatedFrom |
string |
When set | An API key ID, key_…. |
graceEndsAt |
string |
When set | Set on a rotated key: it keeps working until then. |