Kirak HTTP API Reference
The complete wire contract for a deployed Kirak application. This document serves as the authoritative single source of truth for the client SDK (kirak on npm), client tooling, and external API gateways.
1. Base URL, Prefixes, and Transport
Section titled “1. Base URL, Prefixes, and Transport”A deployed Kirak application runs as a single FastAPI service:
| Group | Default Mount | Configurable In kirak.json |
|---|---|---|
| CRUD + GraphQL | / (e.g. /posts/fetch, /graphql) |
routes.crud_prefix (e.g. /api/v1 -> /api/v1/posts/fetch) |
| Auth | /auth/* |
routes.auth_prefix (e.g. /api/auth -> /api/auth/login) |
| Storage | /storage/* |
Mounted at storage module slug (active when storage is enabled) |
| Other Modules & Admin | See Section 10 | routes.module_prefixes per module |
- Payloads: All request and response bodies are JSON (
Content-Type: application/json), except storage file uploads, which usemultipart/form-data. - Path Norms: No trailing slashes on any route.
- Prefix Conflict Safety: If
crud_prefixis empty (default), a model namedstoragewould collide with/storage/*. Give such models distinct names or configure an explicitcrud_prefix.
2. Authentication
Section titled “2. Authentication”Kirak accepts three authentication mechanisms across all endpoints (CRUD, GraphQL, Auth, AI, Storage, Scheduler, Notifications, Payments, Vector, MCP, and Admin).
2.1 User JWT (Browser / Mobile / SPA)
Section titled “2.1 User JWT (Browser / Mobile / SPA)”- Source: Obtained from
POST /auth/login(or registration verify, phone OTP, social login). - Header: Sent as
Authorization: Bearer <accessToken>. - Access Token TTL: Defined by
auth.access_token_expire_minutesorauth.access_token_expire_hoursinkirak.json(default: 15 minutes). Token claims includesub(user ID),role,email,type: "access",jti,iat,exp. Request authorization resolves directly from these signed claims without database round-trips. - Refresh Token Rotation: Refresh tokens expire by default in 14 days and rotate on every use. Calling
POST /auth/refresh-tokeninvalidates the old refresh token and returns a new access and refresh token pair. Persist the newrefreshTokenimmediately. - Reuse Detection: An old refresh token presented within
refresh_token_reuse_interval_seconds(default 10s) is treated as a network retry and receives tokens. Sent after 10s, it is treated as a breach and revokes the entire user session (401 TOKEN_REVOKED).
2.2 Cookie Mode
Section titled “2.2 Cookie Mode”When auth.cookie_name is set in kirak.json, login, token exchange, and refresh routes attach an HttpOnly; Secure; SameSite=Lax cookie holding the access token:
- Browser clients pass
credentials: 'include'and omit theAuthorizationheader. - Requires
cors.originsorcors.allow_origin_regexto match the calling browser origin (wildcards*cannot be used with credentialed cookies). - Same-site subdomains (
app.example.comcallingapi.example.com) share the cookie whenauth.cookie_domainis configured.
2.3 API Keys (Server-to-Server Only)
Section titled “2.3 API Keys (Server-to-Server Only)”- Format:
kirak_prefix + 43 random Base62 characters + 6-character Base62 CRC32 checksum (55 characters total). - Header: Sent as
Authorization: Bearer kirak_.... Invalid checksums fail fast with401 INVALID_API_KEYwithout hitting the database. - Resolution: Resolves to the user ID who created the key. Key expiration defaults to 365 days. Managed via
/auth/api-keys/*.
2.4 Anonymous / Public Access
Section titled “2.4 Anonymous / Public Access”Models whose access block specifies {"role": "*"} permit unauthenticated guest access. Rate limiting still applies, keyed to the client IP address.
3. Response Envelope
Section titled “3. Response Envelope”3.1 Success Envelope
Section titled “3.1 Success Envelope”{ "statusCode": 200, "status": "success", "message": "Fetched 20 records", "data": [...], "pagination": { "limit": 20, "page": 1, "offset": 0, "total": 156, "total_pages": 8, "has_more": true }}- Status Invariant: The HTTP status line always matches
statusCode. paginationis present only whenpageoroffsetwas passed in the request.
3.2 Error Envelope
Section titled “3.2 Error Envelope”{ "statusCode": 403, "status": "error", "error": "PERMISSION_DENIED", "message": "Role 'user' is not authorized to destroy 'posts'", "data": null}error: Stable machine-readable error code.message: Human-readable explanation.details: Optional structured context (e.g.{ "field": "email" },{ "failed_records": [...] }).
3.3 Machine Error Codes
Section titled “3.3 Machine Error Codes”error |
Status | From | Meaning |
|---|---|---|---|
VALIDATION_ERROR |
400 | core | The request, a field value or a GraphQL query is invalid, including a duplicate of a unique field. A route that refuses a well-formed body it cannot process answers 422 with this code (e.g. /monitoring/alerts/evaluate, /scheduler/*). A request body that fails validation lists every invalid field (at most 20) in details.fields, each with field, code and message; so do a module operation’s params that break its spec (missing, wrong type, not allowed, or a key the operation does not take). |
INVALID_JSON |
400 | core | The request body is not valid JSON. |
AUTHENTICATION_ERROR |
401 | core | A credential is required or was rejected. |
PERMISSION_DENIED |
403 | core | The caller’s role may not do this, or not on these records or fields. |
DATABASE_READ_ONLY |
403 | core | The database is read-only (PostgreSQL, set by the host when its storage quota is used): writes and logins are refused, reads still work. |
DATABASE_WRITE_DENIED |
403 | core | The database refused a write: the app’s role may not write (PostgreSQL, a host revokes it to make the app read-only). Reads still work. |
NOT_FOUND |
404 | core | No such route, model or record, or a valid token’s user no longer exists. |
PAYLOAD_TOO_LARGE |
413 | core | The request body is over the limit: kirak.json max_body_mb (default 10 MB), or on a storage upload route its image_max_size / file_max_size plus 1 MB. The message names the limit in bytes. |
RATE_LIMIT_EXCEEDED |
429 | core | Too many requests; retry after the Retry-After header’s seconds. |
LISTING_NOT_SUPPORTED |
501 | core | The admin API cannot list the rate-limit counters here (a Redis that refuses SCAN, as one shared by several apps may). Get or reset one counter by its key instead. |
DATABASE_ERROR |
500 | core | The database operation failed; the details are logged, not returned. |
INTERNAL_ERROR |
500 | core | An unexpected server error. |
SERVICE_UNAVAILABLE |
503 | core | A backing service (Redis) could not be reached; retry later. |
HTTP_ERROR |
varies | core | Any other HTTP error; see statusCode. |
MISSING_TOKEN |
401 | auth | The route needs a credential and none was sent. |
INVALID_TOKEN |
401 | auth | The access or refresh token is malformed or not valid. |
TOKEN_EXPIRED |
401 | auth | The token has expired: refresh an access token, sign in again for a refresh token. |
TOKEN_REVOKED |
401 | auth | The refresh token was revoked (logout, password change or reset, or a reused rotated token ended its session); sign in again. With Redis, an access token issued before a logout of all sessions, a password change or reset, a role change or a deactivation is refused with this code too (auth.access_token_expire_minutes bounds the window without it). |
AUTH_UNAVAILABLE |
503 | auth | A used one-time sign-in code or nonce could not be recorded, an MFA code could not be counted, an access token’s revocation could not be checked or recorded (database or Redis unreachable), an auth route’s rate limit could not be counted (database and Redis both unreachable), or the provider’s signing keys could not be fetched, so the request was not accepted; retry. |
INVALID_API_KEY |
401 | auth | The API key is unknown, revoked or expired. |
ENCRYPTION_KEY_UNKNOWN |
500 | auth | A stored secret (MFA or social sign-in data) cannot be decrypted, usually because the encryption key changed; the operator must restore the key. |
INVALID_CREDENTIALS |
401 | auth | Wrong email or password, or a wrong current password on change-password. |
INVALID_OTP |
401 | auth | The one-time code is wrong or expired. |
INVALID_MFA_CODE |
401 | auth | The MFA or backup code is wrong, or was already used. |
MFA_LOCKED |
401 | auth | 5 MFA codes without a correct one for this user in 15 minutes; the code was not checked; retry after 15 minutes. |
SOCIAL_AUTH_FAILED |
401 | auth | The social provider sign-in did not complete. |
MOBILE_SIGN_IN_NOT_SUPPORTED |
400 | auth | The provider’s native sign-in gives nothing Kirak can check was issued to this app (OAuth 1, SAML, …), or an access token was sent to a provider other than facebook, or a code_verifier was sent for a provider that does not do PKCE; use the web flow with redirect_to, or send id_token / code. |
NONCE_REQUIRED |
401 | auth | auth.social. |
NONCE_MISMATCH |
401 | auth | The nonce does not match the ID token’s nonce claim, or the token has a nonce and none was sent. |
NONCE_REUSED |
401 | auth | This ID token and nonce already signed in once; sign in again. |
INVALID_REDIRECT |
400 | auth | redirect_to is not in auth.redirect_urls, or the PKCE code_challenge is missing, malformed or not S256. |
INVALID_GRANT |
400 | auth | The sign-in code is unknown, expired, already used, or the code_verifier or redirect_to does not match; sign in again. |
SOCIAL_PROVIDER_ERROR |
502 | auth | A social sign-in failed because the provider could not be reached or failed on its side: at /login (OAuth 1 and OpenID 2 providers call the provider there) or when the code is exchanged at the callback or the mobile route. |
SOCIAL_AUTH_CANCELLED |
401 | auth | The user cancelled at the provider; sent to redirect_to as error=SOCIAL_AUTH_CANCELLED. |
SOCIAL_EMAIL_MISSING |
401 | auth | The provider sent no email address (the user did not allow access to it, or the provider has none), so the sign-in cannot find or create an account. For a provider that has no email to send, auth.social. |
SOCIAL_EMAIL_NOT_VERIFIED |
409 | auth | An account has the email of this social sign-in but its own email is not verified, so the sign-in is not linked to it. |
SOCIAL_EMAIL_PRIVATE |
403 | auth | A first GitHub sign-in whose email is private, and auth.social.github.require_public_email is on. The message tells the user to make the email public on GitHub and sign in again. |
MFA_REQUIRED |
403 | auth | The account has MFA and no tokens were issued: send details.mfa_token with an MFA code to mfa_challenge (a password login may instead repeat with mfa_code). From setup_mfa: send code to add another authenticator. |
INVALID_MFA_TOKEN |
401 | auth | mfa_challenge: the mfa_token is invalid, expired (5 minutes) or already used; sign in again. |
MFA_METHOD_LIMIT |
409 | auth | setup_mfa: the user has 5 authenticators already; remove one first. |
ACCOUNT_INACTIVE |
403 | auth | The account is deactivated. |
ACCOUNT_CLOSED |
403 | auth | The account was closed; it cannot sign in. Its data is deleted when auth.account_close_window is over. When its user closed it and auth.account_reopen is on, a sign-in that passed every check carries details.reopen_token, closed_at and purge_at: send the token to reopen_account. |
INVALID_REOPEN_TOKEN |
401 | auth | reopen_account: the reopen token is invalid, expired or used, or the account can no longer be reopened; sign in again. |
ACCOUNT_ALREADY_CLOSED |
409 | auth | close_account: the account is closed already. |
ACCOUNT_NOT_CLOSED |
409 | auth | restore_account: the account is not closed. |
ACCOUNT_PURGE_STARTED |
409 | auth | restore_account: the account’s window is over and its data is being deleted. |
REAUTH_REQUIRED |
401 | auth | close_account for an account without a password: sign in again and close within 5 minutes. |
ACTIVE_SUBSCRIPTION |
409 | auth | close_account: a subscription can still bill the user; cancel it first (details.subscription_ids). |
ACTIVE_MERCHANT_ACCOUNT |
409 | auth | close_account: the user has a merchant account; settle and remove it first. |
EMAIL_NOT_VERIFIED |
403 | auth | The email address must be verified before signing in. Also a first social sign-in whose email the provider did not confirm as verified, when auth.social. |
WEAK_PASSWORD |
400 | auth | The new password does not meet the password rules; message says which. |
INVALID_RESET_TOKEN |
400 | auth | The password reset link is invalid or already used. |
INVALID_VERIFICATION_TOKEN |
400 | auth | The email verification link is invalid or expired, or its account or address no longer exists. |
EMAIL_ALREADY_VERIFIED |
409 | auth | The email address of the verification link is already verified. |
EMAIL_ALREADY_EXISTS |
409 | auth | An account with this email exists. |
REGISTRATION_CLOSED |
403 | auth | auth.registration is closed: register, a first phone-code sign-in and a first social sign-in create no account. |
PHONE_IN_USE |
409 | auth | Another account has this phone number, so it cannot be added to this one. |
KEY_ROTATION_UNAVAILABLE |
409 | auth | rotate_keys: this process runs only per request and the scheduler module is off, so a rotation cannot run in the background; enable the scheduler. |
USER_DATA_ERROR |
500 | auth | The signed-in user’s record could not be read. |
INTEGRATION_UNKNOWN |
404 | integrations | No integration with this name is configured in kirak.json. |
INTEGRATION_NOT_OAUTH |
400 | integrations | The integration is an api_key one, which has no connect flow. |
INTEGRATION_STATE_INVALID |
400 | integrations | The connect link or the provider’s state is invalid, expired, already used, or does not belong to this browser. Start the connection again. |
INTEGRATION_CANCELLED |
400 | integrations | The user refused at the provider, or the provider sent no code. Sent as the error parameter of the return_to redirect. |
INTEGRATION_CONNECT_INVALID |
400 | integrations | A connect value is missing, not declared by the profile, or does not match its pattern. |
INTEGRATION_CONNECTION_LIMIT |
409 | integrations | The app’s limit on connections to this service is reached. |
INTEGRATION_CONNECTION_NOT_FOUND |
404 | integrations | No connection with this id belongs to the user. |
INTEGRATION_PROVIDER_ERROR |
400 | integrations | The provider refused the request, or its answer lacked a value Kirak needs. |
INTEGRATION_PROVIDER_UNAVAILABLE |
502 | integrations | The provider did not answer in time, answered with an error, or its answer cannot be read. The outcome is unknown; try again. |
INTEGRATION_RATE_LIMITED |
429 | integrations | Too many requests for this operation. Wait a minute. |
INTEGRATION_NOT_CONNECTED |
409 | integrations | The user has no connection to this integration. Start a connect. |
INTEGRATION_NEEDS_REAUTH |
409 | integrations | The connection must be made again: the provider no longer accepts its grant. Start a new connect. |
INTEGRATION_CONNECTION_REQUIRED |
400 | integrations | The user has several connections to this integration; pass the connection_id. |
INTEGRATION_USER_REQUIRED |
400 | integrations | The call needs a user: pass user_id, or call as a signed-in user. |
INTEGRATION_PATH_INVALID |
400 | integrations | The path is not a path on the integration’s API (it must start with / and must not hold a scheme, a host or ‘..’). |
INTEGRATION_RESPONSE_TOO_LARGE |
413 | integrations | The provider’s response is larger than 64 KB. |
INTEGRATION_WEBHOOKS_NOT_SUPPORTED |
404 | integrations | The integration’s profile declares no webhooks. |
INTEGRATION_WEBHOOK_BODY_INVALID |
400 | integrations | The webhook body is not JSON. |
INTEGRATION_WEBHOOK_HANDLER_FAILED |
500 | integrations | A webhook handler raised; the provider may send the event again. |
INTEGRATION_SITE_NOT_FOUND |
404 | integrations | The site is not one of the connection’s sites. |
INTEGRATION_CONNECTION_BUSY |
409 | integrations | The connection changed while it was being updated (a refresh). Try again. |
INTEGRATION_APP_GRANT |
400 | integrations | The integration uses the client_credentials grant: users do not connect to it. |
INTEGRATION_APP_TOKEN_REFUSED |
502 | integrations | The provider refused the app’s client credentials grant. |
INTEGRATION_KEY_INVALID |
422 | integrations | The provider does not accept the key, or the key or its label is not in the form Kirak takes. |
INTEGRATION_NOT_USER_KEY |
400 | integrations | Users do not save a key for this instance: it is an oauth2 integration (connect it instead), or an api_key one whose key belongs to the app. |
INTEGRATION_PROXY_NOT_ALLOWED |
403 | integrations | The instance uses the app’s own key (key_owner app), which the proxy routes do not expose. Call it with client() in a route of the app’s own. |
INTEGRATION_HOST_NOT_ALLOWED |
500 | integrations | A call would go to a host that is not the instance’s base_url or allowed_hosts. Refused before anything is sent. |
MONITORING_NO_STORE |
501 | monitoring | The app keeps no monitoring records to read: monitoring.sinks has no sqlite (stdout only). Every read endpoint answers this; /ping and /health still work. Not temporary, so do not retry. |
STORAGE_ERROR |
varies | storage | The storage provider failed to upload, delete, sign a URL for or list files: 502 when it is down or refuses Kirak’s credentials, 400 when it refused the request, 500 otherwise (details.kind). |
4. CRUD Operations
Section titled “4. CRUD Operations”Mounted per model under /{model}/* (where {model} is the model’s slug or name):
| Operation | Method | Path | Request Body / Query Params |
|---|---|---|---|
fetch |
GET | /{model}/fetch |
Query filters + limit, page, offset, order_by, order, select |
search |
GET | /{model}/search |
search + filters + pagination |
count |
GET | /{model}/count |
Filters + optional group_by |
exists |
GET | /{model}/exists |
Filters -> { "data": { "exists": true } } |
fetch, search, count, exists |
POST | /{model}/<operation> |
{ "where": {...}, <options> } – the same read with the filters in a body |
create |
POST | /{model}/create |
{ "data": {...} } (single) or { "data": [...] } (bulk) |
update |
PUT | /{model}/update |
{ "where": {...}, "data": {...} } (where is required) |
upsert |
PUT | /{model}/upsert |
{ "where": {...}, "data": {...} } (where is the primary key, one unique field or one unique index) |
delete |
DELETE | /{model}/delete |
Query filters (id__in=1,2,3 runs in chunks) – Soft delete |
destroy |
DELETE | /{model}/destroy |
Query filters (id__in=1,2,3 runs in chunks) – Hard delete |
restore |
PATCH | /{model}/restore |
{ "where": {...}, "data": {...} } – Un-soft-delete |
4.1 Filter Operators
Section titled “4.1 Filter Operators”REST filter parameters use the field__operator convention. In a query string every key that is not one of the operation’s options is a filter; in a JSON body filters go under where, and any other key the operation does not take is refused (400 VALIDATION_ERROR). All filters are combined with AND. REST strictly prohibits or and or_groups query parameters (400 VALIDATION_ERROR). OR is available on GraphQL reads only: see GraphQL: OR.
| Suffix | SQL Operator | Description |
|---|---|---|
| (none) | = |
Equality |
__ne |
!= |
Inequality |
__gt, __gte |
>, >= |
Greater than, greater than or equal |
__lt, __lte |
<, <= |
Less than, less than or equal |
__like, __ilike |
LIKE, ILIKE |
Text pattern match. Preserves explicit % wildcards |
__in, __not_in |
IN, NOT IN |
Comma-separated list or JSON array |
__between |
BETWEEN ... AND ... |
Array of exactly two items |
__is_null |
IS NULL |
Evaluates boolean presence |
__is_not_null |
IS NOT NULL |
Evaluates non-null presence |
5. GraphQL
Section titled “5. GraphQL”POST /graphql
{ "query": "query { posts(status: \"published\", limit: 10) { id title created_at } }"}- Returns the canonical Kirak response envelope.
- Enforces identical RBAC and RLS permissions as REST.
- Multi-root mutations execute within a single atomic database transaction.
- Request budgets: maximum 20,000 tokens, 50 root fields, and 1,000 selections.
- Schema introspection (
__schema,__type) is disabled (403 PERMISSION_DENIED).
6. Authentication Endpoints
Section titled “6. Authentication Endpoints”Mounted under /auth/*:
6.1 Session Management
Section titled “6.1 Session Management”| Route | Method | Request Payload | Description |
|---|---|---|---|
/auth/login |
POST | { email, password, mfa_code?, device_token? } |
Authenticates user; returns { user, accessToken, refreshToken, expiresIn } |
/auth/register |
POST | { email, password, first_name?, last_name? } |
Registers account. Role is forced to "user". Sends verification email. |
/auth/refresh-token |
POST | { refreshToken } |
Rotates refresh token; returns new token pair |
/auth/logout |
POST | { token, logout_type? } |
Revokes sessions (single, all, others) |
/auth/me |
GET | (Bearer) | Returns current authenticated user record |
/auth/close-account |
POST | { password?, reason?, user_id? } (Bearer) |
Requests account closure with grace period retention. Clears auth cookie. |
/auth/keys/rotate |
POST | { old_key?, new_key? } (Bearer admin/system) |
Re-encrypts user data with new encryption key (returns 202 Accepted). |
6.2 Password & Email Lifecycle
Section titled “6.2 Password & Email Lifecycle”| Route | Method | Request Payload | Description |
|---|---|---|---|
/auth/change-password |
POST | { current_password, new_password, confirm_password } (Bearer) |
Updates password and revokes existing sessions |
/auth/request-reset-password |
POST | { email } |
Dispatches password reset link |
/auth/reset-password |
POST | { token, new_password, confirm_password } |
Sets new password via token |
/auth/verify-email |
GET | ?token=... |
Verifies user email via link |
/auth/email/change |
POST | { new_email } (Bearer) |
Initiates email change flow |
6.3 Phone OTP & Multi-Factor Authentication
Section titled “6.3 Phone OTP & Multi-Factor Authentication”| Route | Method | Request Payload | Description |
|---|---|---|---|
/auth/request-otp |
POST | { phone_number } (E.164) |
Sends SMS verification code |
/auth/verify-otp |
POST | { phone_number, otp } |
Verifies code and logs in / creates account |
/auth/setup-mfa |
POST | { name?, code? } (Bearer) |
Generates TOTP secret and QR provisioning URI |
/auth/verify-mfa |
POST | { code, action: "activate" } (Bearer) |
Confirms TOTP setup and issues backup codes |
/auth/mfa/challenge |
POST | { mfa_token, code } |
Completes MFA login challenge |
6.4 API Key Management
Section titled “6.4 API Key Management”| Route | Method | Request Payload | Description |
|---|---|---|---|
/auth/api-keys/create |
POST | { name, expires_at?, scopes? } (Bearer) |
Generates a persistent API key (kirak_...). Returns key once. |
/auth/api-keys/list |
GET | – (Bearer) | Lists active API keys and scopes for authenticated user. |
/auth/api-keys/revoke |
DELETE | { id?, key_prefix? } (Bearer) |
Revokes key by record ID or 14-character prefix. |
7. Storage Endpoints
Section titled “7. Storage Endpoints”Mounted under /storage/* (requires active authentication):
| Route | Method | Description |
|---|---|---|
/storage/upload/image |
POST multipart | Uploads image, applies compression, and generates thumbnails |
/storage/upload/file |
POST multipart | Uploads raw document or asset |
/storage/delete |
DELETE | Deletes file (and optional thumbnail variants) |
/storage/url |
GET | Generates presigned download URL for private instances |
/storage/list |
GET | Lists files within a path prefix |
Non-admin callers are confined to paths under their {user_id}/ folder.
8. Other System Endpoints
Section titled “8. Other System Endpoints”| Routes | Access | Description |
|---|---|---|
GET /admin/rate-limits |
Admin | Inspect or reset rate limit counters |
GET /docs, GET /openapi.json |
Public / Configured | Machine & human readable API documentation |
GET /media/{instance}/{path} |
Public / Signed | Static file serving for local storage instances |
/ai/* |
Configured | Prompts, agent sessions, and approvals |
/scheduler/* |
Configured | Job status, queue status, and manual task triggers |
/notifications/* |
Configured | Message dispatch and inbox preferences |
/payments/* |
Configured | Checkout sessions, customers, and webhooks |
/integrations/* |
Configured | OAuth connection management and API proxy |
/monitoring/* |
Bearer | Prometheus metrics, health checks, and traces |
/mcp/<server>/ |
Bearer | Model Context Protocol AI tools endpoint |