Skip to content

Create a new API key for the current tenant

POST
/v1/auth/api-keys
curl --request POST \
--url https://api.emite.cr/v1/auth/api-keys \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{ "name": "Production integration", "environment": "sandbox", "scopes": [ "invoices:write", "invoices:read", "parties:read" ], "expiresAt": "2027-01-01T00:00:00.000Z" }'

Returns the plaintext key ONLY in this response — it is hashed before storage. Use the key via the x-api-key request header. Requires the api_keys:manage scope, granted to the owner and admin roles; not grantable to API keys (a key cannot mint another). Pass an explicit list of Scope values for least-privilege.

Media typeapplication/json
object
name
required

Human-friendly label shown in the dashboard. Max 80 chars.

string
<= 80 characters
Example
Production integration
environment
required

Environment scope for the key. Stripe-style: a key is bound to ONE environment at creation and cannot cross over. The prefix segment of the raw key reflects this: ec_test_* for sandbox, ec_live_* for production. Inmutable post-creación.

string
Allowed values: sandbox production
Example
sandbox
scopes
required

Permission scopes — REQUIRED and non-empty (AUD-1). Pass "*" for an explicit admin key, which grants every OPERATIONAL scope but never the JWT-only ones (billing:*, credentials:*, members:*, ownership transfer, key management, sandbox reset). Omitting the field used to mean "unrestricted" — that sentinel is gone: an empty list now grants nothing, and minting a key without saying what it may do is rejected with API_KEY_SCOPES_REQUIRED. Pre-existing keys stored with [] keep working (resolved at verification time). See apps/web/messages/{es,en}.json settings.apiKeys.scopes.* for human labels.

Array<string>
Allowed values: invoices:read invoices:write invoices:sign invoices:submit invoices:void invoices:export proformas:read proformas:write recurring:read recurring:write recurring:run documents:read documents:accept parties:read parties:write items:read items:write branches:read terminals:read sequences:read tenant:read settings:read economic_activities:read fx:read reports:read reports:export fiscal:write webhooks:manage audit:read *
Example
[
"invoices:write",
"invoices:read",
"parties:read"
]
expiresAt

Expiration timestamp. After this moment the key is rejected with 401. Omit for a non-expiring key (recommended only for short-lived integrations).

string format: date-time
Example
2027-01-01T00:00:00.000Z

CreatedApiKeyResponseDto including the plaintext rawKey value (one-time view).

Media typeapplication/json
object
id
required

Identifier of the key — also the middle segment of the raw key (<prefix>_<id>_<secret>). Use it to rotate or revoke the key.

string
name
required

The label given at creation, kept by a rotation. Unique among the active keys of the environment: a revoked key frees its name.

string
prefix
required

Prefix segment of the raw key. ec_test_* for sandbox keys, ec_live_* for production keys (Stripe-style). The secret segment is never returned after creation (the middle segment is the key's id).

string
environment
required

Environment the key is bound to. A sandbox key authenticates against sandbox data only; a production key against production data only. Immutable after creation — to switch environments, create a new key.

string
Allowed values: sandbox production
lastFour
required

Last 4 chars of the key id. Useful for visual reconciliation in the UI and in audit logs ("the key ending in …a3b4"). NEVER exposes secret bytes.

string
scopes
required

The scopes stored on the key, as chosen at creation (a rotation keeps them). * grants every scope an API key may hold — never the session-only ones (members, API keys, billing, credentials, ownership).

Array<string>
status
required

Derived, never stored: revoked once revokedAt has passed (it wins over an expiry), expired once expiresAt has passed, otherwise active — also during the grace window of a rotation, while revokedAt is still in the future.

string
Allowed values: active revoked expired
createdAt
required

When the key was created (a rotation creates a new key).

string format: date-time
lastUsedAt
required

Last verified use (best-effort, populated on guard verify).

string format: date-time
nullable
expiresAt
required

When the key stops authenticating on its own, as set at creation (a rotation keeps it). null = it never expires.

string format: date-time
nullable
revokedAt
required

When the key was revoked; null if it never was. A rotation sets it in the future — the grace window — and the old key keeps working until then.

string format: date-time
nullable
createdByName
required

Display name of the user who created the key. null if the user was deleted.

string
nullable
createdByUserId
required

User who created the key.

string format: uuid
nullable
rawKey
required

Plaintext API key. Returned once only. Use as the x-api-key header value. Cannot be recovered after this response.

string
Example
{
"environment": "sandbox",
"status": "active",
"rawKey": "ec_test_01a00c73-5c07-7bb5-8b9e-d20f16537e42_aBcDeF..."
}

Missing or invalid JWT.

API key management requires a JWT session — API keys cannot mint other keys.