Skip to content
Svanja

Docs API reference

API keys

Create, change, replace and revoke the team's API keys from code.

These endpoints let you manage your team’s API keys from code. They work with the same keys you see in Settings under API Keys, which is handy if you want to rotate keys on a schedule or issue limited-access keys for your own tools.

To call these endpoints, your key needs access to the API keys area. Read-only keys don’t have it, and only a Full access key can grant another key permission to manage keys. A key can never give another key more access than it has itself. For more on what keys are and how access works, see The REST API.

POST /api-keys creates a new key, and POST /api-keys/{apiKey}/rotate replaces an existing one. Both return the new secret only once in data.access_token, so save it right away. When you rotate a key, the old one stops working immediately, and the new one keeps the same name, access, and expiration.

A key can update its own display name. To rotate it, revoke it, or change its access, you’ll need to use the app or another key with the right permissions.

The CLI sign-in endpoints (/cli-auth/...) are what svanja login uses to fetch a key through your browser. They don’t require an API key and aren’t meant for your own code.

Operations

An operation is one thing you can do, like reading a task or starting one. Its effect says what it changes. Some operations that act outside Svanja or change access wait for a person's approval; the approval flow is on the API overview.

api_key.read Reads only

Read team API keys.

GET /api-keys GET /api-keys/{apiKey}

api_key.write Changes access or automation

Create or manage API keys.

POST /api-keys PATCH /api-keys/{apiKey} POST /api-keys/{apiKey}/rotate POST /api-keys/{apiKey}/revoke

Endpoints

Paths start at https://app.svanja.com/api/v1. Every endpoint needs an API key unless it says otherwise. A required Idempotency-Key header is listed with the parameters.

GET /api-keys List API keys

Lists non-secret metadata for API keys in the authenticated team. Requires API key read management capability.

Parameter In Type Required Notes
page query integer no Page number. Defaults to 1.
per_page query integer no Page size. Defaults to 25 and is capped at 100.

Status codes: 200, 401, 403, 422, 429

POST /api-keys Create an API key

Creates an API key and returns the plaintext bearer value once. This secret-issuing endpoint rejects Idempotency-Key and is not replayable.

Body field Type Required Notes
name string yes
preset one of full_access, read_only, custom no
group_selections array of object no
project_scope one of all_projects, selected_projects no
selected_project_public_ids array of string no
expires_at string or null no

Status codes: 201, 400, 401, 403, 422, 429

GET /api-keys/{apiKey} Show an API key

Shows non-secret metadata for one API key by display id. Missing, malformed, cross-team, deleted-token, and sidecar-missing targets return resource_not_found after the read capability check.

Parameter In Type Required Notes
apiKey path string yes API key display id in ak_<ULID> form. This is not the internal numeric token row id.

Status codes: 200, 401, 403, 404, 429

PATCH /api-keys/{apiKey} Update an API key

Partially updates API key metadata from JSON body fields only. The final target state must fit within the managing key's capabilities, project scope, selected projects, and lifetime. This non-secret write supports idempotency replay.

Parameter In Type Required Notes
apiKey path string yes API key display id in ak_<ULID> form. This is not the internal numeric token row id.
Idempotency-Key header string no Optional key for unsafe bearer writes. Reusing the same key and same canonical body replays the original response for 24 hours; reusing it with a different body returns idempotency_conflict.
Body field Type Required Notes
name string no
preset one of full_access, read_only, custom no
group_selections array of object no
project_scope one of all_projects, selected_projects no
selected_project_public_ids array of string no
expires_at string or null no

Status codes: 200, 400, 401, 403, 404, 409, 422, 429

POST /api-keys/{apiKey}/rotate Rotate an API key

Revokes the source key and creates a replacement with the same configuration. The plaintext replacement bearer value is returned once. This secret-issuing endpoint rejects Idempotency-Key.

Parameter In Type Required Notes
apiKey path string yes API key display id in ak_<ULID> form. This is not the internal numeric token row id.
Body field Type Required Notes
expires_at string or null no Required only when rotating an expired source key.

Status codes: 200, 400, 401, 403, 404, 409, 422, 429

POST /api-keys/{apiKey}/revoke Revoke an API key

Soft-revokes a same-team non-self API key. Repeated revoke calls are idempotent no-ops and this non-secret write supports idempotency replay.

Parameter In Type Required Notes
apiKey path string yes API key display id in ak_<ULID> form. This is not the internal numeric token row id.
Idempotency-Key header string no Optional key for unsafe bearer writes. Reusing the same key and same canonical body replays the original response for 24 hours; reusing it with a different body returns idempotency_conflict.

Status codes: 200, 401, 403, 404, 409, 422, 429

GET /cli-auth/discovery Discover CLI device authorization settings

Returns stable feature status and endpoint metadata for first-party CLI login. This endpoint intentionally runs before a bearer key exists.

This endpoint works without an API key.

Status codes: 200, 429

POST /cli-auth/device Create a CLI device authorization request

Creates a short-lived browser authorization request and returns the plaintext device code once. CLI metadata is optional and sanitized.

This endpoint works without an API key.

The body takes one of several shapes; see the OpenAPI document for each.

Body field Type Required Notes
client_kind string no Forbidden in the legacy omitted-client-kind request arm.
preset string no Forbidden unless client_kind is local_agent.
group_selections array of object no Forbidden unless client_kind is local_agent.
project_scope string no Forbidden unless client_kind is local_agent.
selected_project_public_ids array of object no Forbidden unless client_kind is local_agent.
expires_at string no Forbidden unless client_kind is local_agent.
client_name string or null no Optional client-declared name. Control characters are sanitized.
cli_version string or null no Optional client-declared version metadata. Control characters are sanitized.
key_name string or null no Optional API key name. null is treated as omitted. A non-null value must be non-empty after sanitization. When omitted or null the key is named "Svanja CLI", or "Svanja CLI (<client_name>)" when client_name is present.

Status codes: 200, 400, 404, 422, 429

POST /cli-auth/token Poll for CLI device authorization completion

Polls a pending device authorization request. It returns an issued API key once after browser approval, or a public polling error while the request is pending, denied, expired, invalid, unsupported, or too fast.

This endpoint works without an API key.

Body field Type Required Notes
grant_type always "urn:ietf:params:oauth:grant-type:device_code" yes
device_code string yes

Status codes: 200, 400, 404, 422, 429

This page as plain Markdown, for AI tools: api-keys.md

Try Svanja with your own mailbox

Sign up now, and you get an email when your account is ready.