Mint an API key
const url = 'https://example.com/v1/tokens';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"for":{"kind":"user","id":"example"},"role":"admin","capabilities":["example"],"label":"example","expiresAt":"2026-04-15T12:00:00Z","projectId":"2489E9AD-2EE2-8E00-8EC9-32D5F69181C0","readOnly":true}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://example.com/v1/tokens \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "for": { "kind": "user", "id": "example" }, "role": "admin", "capabilities": [ "example" ], "label": "example", "expiresAt": "2026-04-15T12:00:00Z", "projectId": "2489E9AD-2EE2-8E00-8EC9-32D5F69181C0", "readOnly": true }'An API key acts for one principal (for: a person or a service account; default the caller), with that principal’s grants. Its role is a ceiling under them and its projectId a limit. Returns the plaintext token exactly once. A person or a service account’s key mints its own keys; only a tenant admin mints for someone else, or an admin key. A caller can only grant capabilities it holds, and a key limited to a project mints only keys limited to it. A key that expires mints only keys that expire no later than it, and a session opened by token sign-in mints as the key it was opened with. A key minted with a key (mintedWith: the caller’s, or the one a token sign-in session was opened with) stops when that key is revoked. Only mounted when the deployment supplies a TokenAdmin.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Header Parameters
Section titled “Header Parameters”Request Body
Section titled “Request Body”A new API key. for is whom it acts for: the caller by default; only a tenant admin mints for someone else.
object
Responses
Section titled “Responses”Token minted.
The new key, plus its secret.
object
Example
{ "principal": { "kind": "user" }, "role": "admin"}Malformed request body, or the body’s projectId isn’t a project id (a UUID).
object
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}Missing / malformed / expired / revoked bearer token.
object
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}Not a tenant admin where one is needed, or a capability the caller does not hold (permission-denied); an admin key for a principal that isn’t a tenant admin (role-exceeds-principal); a key limited to a project minting for another (key-project-mismatch); a key that would outlive the key minting it, with an expiresAt later than that key’s or none (token-expiry-exceeds-minter, its details.latestExpiresAt the latest allowed); a session limited to a project or a role, which mints no keys (limited-session-cannot-mint); a key for a person a site signs in, whose access is only the sessions their site gives (site-person-grants-managed); a key that only reads, which mints no keys (read-only-key); an operator’s capability, which is a system key’s: a system scope (system:*) anywhere, and kindgi:system on a runtime serving many tenants or on a key limited to a project (capability-not-mintable, its details.capabilities the ones refused).
object
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}The body’s projectId names no project of this workspace (project-not-found), or for names no person or service account (principal-not-found).
object
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}for names a project’s own service account, which has no keys (service-account-project-owned). Or Idempotency-Key reused with a different body (idempotency-key-body-mismatch), or a retry of a request that succeeded: its answer carried a secret, which isn’t kept (idempotency-key-replay-withheld, with its status and at). Or idempotency-key-in-flight (with Retry-After): a request with the same Idempotency-Key still runs, so this one wasn’t run; send it again after Retry-After to get that request’s answer.
object
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}Headers
Section titled “Headers”The request body is over the API’s limit (request-too-large; details.maxBytes says how much).
object
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}rate-limit-exceeded with details.limit: "api-requests", on a runtime that sets workspace limits (Kindgi Cloud): this workspace’s limit on API requests a minute is reached, so the request wasn’t run; Retry-After says when to send it again.
object
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}Headers
Section titled “Headers”Server error (unmapped domain code or framework crash).
object
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}readOnly asked of a runtime whose key store can’t keep it (read-only-unsupported): no key was made.
object
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}The Idempotency-Key store (idempotency-store-unavailable) or the authorization store (authz-backend-unavailable) couldn’t be reached before the request ran, or the database was too busy for its authorization check (database-busy), so nothing was changed; Retry-After (whole seconds) says when to try again with the same key. Or tenant-state-unavailable (with Retry-After), on a runtime serving many workspaces: the workspace’s state couldn’t be read, so nothing was changed.
object
Examplegenerated
{ "error": { "code": "example", "message": "example", "details": {}, "requestId": "example" }}Headers
Section titled “Headers”See also
GET /v1/tokens: List API keys- People, API keys and service accounts
- Kindgi 0.7.0
- Error code
authz-backend-unavailable - Error code
capability-not-mintable - Error code
database-busy - Error code
idempotency-key-body-mismatch - Error code
idempotency-key-in-flight - Error code
idempotency-key-replay-withheld - Error code
idempotency-store-unavailable - Error code
key-project-mismatch - Error code
limited-session-cannot-mint - Error code
permission-denied - Error code
principal-not-found - Error code
project-not-found - Error code
rate-limit-exceeded - Error code
read-only-key - Error code
read-only-unsupported - Error code
request-too-large - Error code
role-exceeds-principal - Error code
service-account-project-owned - Error code
site-person-grants-managed - Error code
tenant-state-unavailable - Error code
token-expiry-exceeds-minter - Every error code