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. When you cannot set a header, pass the token in the access_token query parameter instead.

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',
  workspace: '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',
  workspace: '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.

Authenticate with a Query Parameter

For clients that cannot set request headers — MCP over HTTP, EventSource/SSE connections, or a URL opened directly in the browser — pass the token in the access_token query parameter. It accepts any API key or access token and authenticates the request exactly like the Authorization header.

Fetch all articles with the token in the query string:

curl "https://example.monospace.io/api/blog/items/articles?access_token=YOUR_API_KEY"
The SDK always sends the token in the Authorization header, so there is no query-parameter option to configure. See Client Setup.
Query strings are recorded in browser history, proxy and web-server access logs, and Referer headers. Monospace redacts the access_token value from its own request logs, but cannot control intermediaries. Prefer the Authorization header, and use the query parameter only when you cannot set one.

Provide the token through exactly one source. Combining the query parameter with an Authorization header or a session cookie fails, as does repeating the parameter:

RequestResult
?access_token=<token> aloneAuthenticated
?access_token= (empty value)401 UnauthorizedInvalid token
?access_token=<token> with a Bearer header or session cookie400 Bad RequestInvalid request
?access_token=<a>&access_token=<b> (repeated)400 Bad RequestInvalid request

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 MONOSPACE_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

Credential Sources

The server reads credentials from three sources:

  1. Authorization: Bearer <token> header
  2. access_token query parameter
  3. Session cookie (set by session-mode login)

Provide exactly one. A request that supplies two or more sources — for example a Bearer header alongside a session cookie — fails with 400 Bad Request. A malformed Authorization header counts as a source, so pairing it with any other credential also returns 400. A malformed header on its own returns 401 Unauthorized.


See Also

  • Errors — status codes and the error response shape
  • MCP — connect an MCP client, a common consumer of the access_token query parameter
  • SDK setup — configure the SDK for your project
  • API overview — understand URL structure and response format
Copyright © 2026