Create an API key
POST /v1/api-keys
| Property | Value |
|---|---|
| Operation | create_api_key |
| Group | API keys |
| Scope | api_keys:write |
| Route class | control |
| Idempotency | Idempotency-Key accepted: a retry with the same key replays the first answer |
| Audit | Audited identity.api_key.create (mutation) |
| Released in | 1.51.0 |
| Phase 0 host | Served (the hosted api pins 1.65.0) |
Creates an active key of the caller's Organization for one environment and answers ApiKeyCreated, the one answer that shows the full key (1.51.0, FR-identity-2); the api stores a per-key salt, the SHA-256 of salt and secret, and the prefix. A replay under the same Idempotency-Key creates nothing and answers secret null. A scope no API key may exercise is refused with validation_failed and the issue scope_session_only at /scopes/<i>, and an expires_at that is not in the future with expires_at_not_future; a scope the creator's role does not hold is refused with forbidden and the detail scope_not_grantable at /scopes/<i>, and a live key asked by a role that manages test keys only with the detail environment_not_grantable at /environment. From 1.57.0 (workspace ADR 0048 decision 2) a content scope (transcripts:read, tool_payloads:read, model_io:read, recordings:read) whose class the creator's role does not have allowed in the Compliance profile's content_visibility is refused with validation_failed and the issue content_scope_not_allowed at /scopes/<i> (contentScopeIssues), so a Member limited to reveal cannot mint a key that reads without a grant. The Audit event identity.api_key.create records the key id, its environment and its scopes, never the secret. Session only (api.md section 2): the api refuses the route to every API key with forbidden, whatever its scopes; Phase 0 accepts a Member ID token.
Request
Set VOCAL_API to the base URL of your API and VOCAL_API_KEY to an API key with the api_keys:write scope (Authentication and keys). Replace each placeholder, such as agt_... or <name>, with your own value.
curl -X POST "$VOCAL_API/v1/api-keys" \
-H "Authorization: Bearer $VOCAL_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"name": "<name>",
"environment": "live",
"scopes": [
"agents:read"
]
}'const response = await fetch(`${process.env.VOCAL_API}/v1/api-keys`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.VOCAL_API_KEY}`,
'Idempotency-Key': crypto.randomUUID(),
'Content-Type': 'application/json',
},
body: JSON.stringify({
"name": "<name>",
"environment": "live",
"scopes": [
"agents:read"
]
}),
});
console.log(response.status, await response.text());import os
import uuid
import requests
response = requests.post(
f"{os.environ['VOCAL_API']}/v1/api-keys",
headers={
"Authorization": f"Bearer {os.environ['VOCAL_API_KEY']}",
"Idempotency-Key": str(uuid.uuid4()),
},
json={
"name": "<name>",
"environment": "live",
"scopes": [
"agents:read",
],
},
)
print(response.status_code, response.text)Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
idempotency-key | header | string | no | A client-chosen key, kept 24 hours per Organization, environment and route. A replay returns the stored response. |
Request body
Content type application/json, required: ApiKeyCreateRequest.
| Field | Type | Required | Description |
|---|---|---|---|
environment | Environment | yes | |
expires_at | RequestTimestamp | no | When the key stops authenticating, in the future (expires_at_not_future); absent, the key does not expire. |
name | string | yes | A name for the console, such as ci. |
scopes | array of ApiKeyScope | yes | The permissions the key holds, each once: never one of SESSION_ONLY_PERMISSIONS (scope_session_only), never one the creator's role does not hold (forbidden with scope_not_grantable), and from 1.57.0 never a content scope whose class the creator's visibility cell does not allow (content_scope_not_allowed). |
Responses
| Status | Content type | Shape | Error codes |
|---|---|---|---|
201 | application/json | ApiKeyCreated | |
400 | application/json | ErrorEnvelope | invalid_request |
401 | application/json | ErrorEnvelope | unauthenticated |
403 | application/json | ErrorEnvelope | forbidden, org_suspended |
409 | application/json | ErrorEnvelope | idempotency_in_progress, idempotency_key_reused |
422 | application/json | ErrorEnvelope | validation_failed |
429 | application/json | ErrorEnvelope | rate_limited |
500 | application/json | ErrorEnvelope | internal_error |
Fields of the 201 answer
The shape is ApiKeyCreated.
| Field | Type | Required | Description |
|---|---|---|---|
created_at | Timestamp | yes | |
created_by | ActorRef or null | no | Who made the key (1.52.0): {type: member, id} for a key created through POST /v1/api-keys, {type: operator, id} for one the seed or an operator command made when the api records it, and null when it does not. Absent from an api before 1.52.0. A removed Member keeps its id here; the keys it made stay. |
environment | Environment | yes | |
expires_at | Timestamp or null | yes | |
id | ApiKeyId | yes | |
last_used_at | Timestamp or null | yes | |
name | string | yes | |
object | "api_key" | yes | |
prefix | string | yes | The non-secret start of the key, vk_<env>_<lookup>; the full key is vk_<env>_<lookup>_<secret>. |
revoked_at | Timestamp or null | yes | |
scopes | array of ApiKeyScope | yes | |
secret | ApiKeySecret or null | yes | The full key (1.51.0), shown in this answer only and never again; null on a replay of the creation under the same Idempotency-Key, which creates nothing. |
status | ApiKeyStatus | yes |