Data Access

Authentication

Authenticate your requests to the Monospace API.

Authentication Methods

Monospace supports three authentication methods:

MethodUse CaseTransport
API KeyServer-to-server, scripts, CI/CDAuthorization: Bearer <jwt> header
Email/Password LoginUser sessions, browser appsAccess token (header or cookie) + refresh token
Access TokenObtained from login, short-livedAuthorization: Bearer <jwt> header

All tokens are JWTs signed with EdDSA (Ed25519). API keys and access tokens are sent the same way — as a Bearer token in the Authorization header.

Get an API Key

In the Studio, go to Account Settings > Access to create and manage your API keys. Each key is a JWT scoped to a specific user and inherits their permissions.

Manage API Keys

EndpointMethodDescription
/api/system/api-keysPOSTCreate a new API key
/api/system/api-keysGETList all API keys
/api/system/api-keys/{key_id}PATCHUpdate a key (name, description, active)
/api/system/api-keys/{key_id}DELETEDelete a key

API keys can be deactivated without deletion by setting active: false.

Service Accounts

For machine-to-machine access, create a service account and attach API keys to it.

EndpointMethodDescription
/api/system/service-accountsPOSTCreate a service account
/api/system/service-accountsGETList service accounts
/api/system/service-accounts/{id}GETRead a service account
/api/system/service-accounts/{id}PATCHUpdate a service account
/api/system/service-accounts/{id}DELETEDelete a service account

Service accounts are user records with isService: true, owned by a real user via the serviceAccountOwner relation. As an organization admin, you can create service accounts in Organization Settings > Service Accounts.

Authenticate REST Requests

Pass the API key in the Authorization header using the Bearer scheme.

Fetch all articles with an authenticated request:

import { createClient } from './generated/monospace';

const client = createClient({
  url: 'https://example.monospace.io',
  project: 'blog',
  apiKey: 'YOUR_API_KEY',
});

const articles = await client.Articles.readMany();

Create a new article with a POST request:

import { createClient } from './generated/monospace';

const client = createClient({
  url: 'https://example.monospace.io',
  project: 'blog',
  apiKey: 'YOUR_API_KEY',
});

const article = await client.Articles.createOne({
  data: {
    title: 'Auth Guide',
    author: 'alice',
    status: 'draft',
  },
  fields: ['id', 'title', 'status'],
});
The SDK attaches the Authorization header automatically when configured with an apiKey. See Client Setup for configuration.
Never expose API keys in client-side code or public repositories.

Email/Password Login

For user-facing applications, authenticate with email and password. The login endpoint supports two modes.

JSON Mode

Returns access and refresh tokens in the response body:

curl -X POST https://example.monospace.io/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"credentials": {"email": "user@example.com", "password": "secret"}, "mode": "json"}'

Response:

{
  "expires": 900,
  "accessToken": "eyJ...",
  "refreshToken": "eyJ..."
}

Use the accessToken as a Bearer token for subsequent requests, just like an API key.

Session Mode (default)

Sets httpOnly cookies for the access and refresh tokens. This is the default when mode is omitted:

curl -X POST https://example.monospace.io/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"credentials": {"email": "user@example.com", "password": "secret"}}' \
  -c cookies.txt

In session mode, ensure your HTTP client sends cookies with each request (e.g. credentials: 'include' in fetch).

Refresh and Logout

Refresh an Access Token

curl -X POST https://example.monospace.io/api/auth/refresh \
  -H "Content-Type: application/json" \
  -d '{"refreshToken": "eyJ..."}'
Refresh tokens have a server-configured TTL (set via DIRECTUS_REFRESH_TOKEN_TTL). Once expired, you must re-authenticate. For production applications:
  • Store only the latest refresh token — each refresh call may return a new one.
  • Handle refresh failures (expired or revoked tokens) by prompting re-login.
  • Prefer session mode for browser apps — the server manages token lifecycle via httpOnly cookies automatically.

Log Out

Invalidates the refresh token:

curl -X POST https://example.monospace.io/api/auth/logout \
  -H "Content-Type: application/json" \
  -d '{"refreshToken": "eyJ..."}'

Auth Endpoints Reference

EndpointMethodDescription
/api/auth/loginPOSTEmail/password login
/api/auth/refreshPOSTRefresh access token
/api/auth/logoutPOSTInvalidate refresh token
/api/auth/password-changePOSTChange password (requires auth)
/api/auth/password-reset/requestPOSTRequest password reset email
/api/auth/password-reset/verifyGETVerify reset token
/api/auth/password-reset/confirmPOSTConfirm password reset

Token Extraction Priority

The server checks for authentication in this order:

  1. Authorization: Bearer <token> header
  2. Session cookie (fallback if header is missing)

If the header is present but malformed, the request fails — it does not fall through to the cookie.


Next steps:

  • SDK setup — configure the SDK for your project
  • API overview — understand URL structure and response format
Copyright © 2026