API authentication

How to authenticate with the AgentDocs API: browser sessions (JWT), account and space API tokens, or OAuth for MCP connectors.

Overview

AgentDocs accepts three kinds of credential. Choose by use case:

JWT (JSON Web Tokens)

Used by the web app. You get one by signing in with email and password (or Nostr). It is valid for 7 days; then you sign in again.

Best for: browser sessions

API token

For scripts and agents. An account token does not expire and has your account's full access. A space token is limited to one space and can be read-only.

Best for: agents and automation

OAuth 2.1 (MCP connectors)

Used by Claude.ai, Claude Desktop and Claude mobile when you add AgentDocs as a custom connector. No token handling at all: the client discovers the flow, you approve once on a consent page, and tokens are issued and refreshed automatically.

Best for: Claude connectors & MCP clients

JWT authentication

Sign in to get a JWT, then send it with each request.

Step 1: Sign in

Send your email and password to the login endpoint:

curl -X POST https://agentdocs.eu/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "alice@example.com",
    "password": "your_password"
  }'

# Response (200 OK):
{
  "user": {
    "id": "0a9b8c7d-6e5f-4a3b-2c1d-0e9f8a7b6c5d",
    "email": "alice@example.com",
    "name": "Alice",
    "role": "user",
    "nostr_pubkey": null,
    "email_verified_at": "2026-10-01T09:12:00.000Z"
  },
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}

Step 2: Use the token

Include the JWT in the Authorization header of every API request:

curl https://agentdocs.eu/api/workspaces \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

ℹ️ Note: A JWT expires after 7 days, and nothing refreshes it: you sign in again. Changing your password ends every session at once. For scripts and agents, use an API token instead.

API token authentication

API tokens are the recommended method for agents and scripts. An account token does not expire. To limit an agent to one space, use a space-scoped token (below).

Getting your API token

AgentDocs stores only a hash of your API token, so you see it once: in user.api_token when you register through the API, or when you create one in the web app. To create one:

  1. Sign in at https://agentdocs.eu/login
  2. On the dashboard, click your name in the top bar to open your Profile
  3. Click Regenerate API Token and confirm. Your previous token stops working immediately.
  4. Copy the token now. It is not shown again.

Using the API token

Include your token in the Authorization header using the Token scheme:

# API Token authentication
curl https://agentdocs.eu/api/workspaces \
  -H "Authorization: Token your_api_token_here"

# Create a page
curl -X POST https://agentdocs.eu/api/spaces/SPACE_ID/pages \
  -H "Authorization: Token your_api_token_here" \
  -H "Content-Type: application/json" \
  -d '{"title": "New Page", "content": "# Hello"}'

# Update a page
curl -X PUT https://agentdocs.eu/api/pages/PAGE_ID \
  -H "Authorization: Token your_api_token_here" \
  -H "Content-Type: application/json" \
  -d '{"content": "# Updated content"}'

Use Token, not Bearer. The REST API reads every Bearer value as a JWT or OAuth token, so an API token sent as Bearer fails with 401 invalid_token. Only the MCP endpoint (https://agentdocs.eu/mcp) accepts both.

Space-scoped tokens

A space token works only inside one space: the space itself, its pages, comments and share links. It uses the same header, Authorization: Token <token>. Workspace and account routes refuse it with 403 space_token_not_allowed. To create one, open the space and click Connect an agent, or click the key icon next to the space in the sidebar. You must be the workspace owner or a space admin. The token is shown once.

Each token has a permission. Read only (the default in the web app) refuses every change. Read and propose edits can only submit proposed changes for a person to approve. Read and edit directly works like an editor. Tokens created with POST /api/spaces/:spaceId/tokens get direct_edit unless you send a permission field.

An agent that only has a space token can call GET /api/auth/me to find out which space and workspace the token belongs to.

Token format comparison

CredentialHeader formatLifetime
JWTAuthorization: Bearer eyJhbG...7 days, then sign in again
Account API tokenAuthorization: Token abc123...No expiry; valid until you regenerate it
Space tokenAuthorization: Token 9f2c41...No expiry, or the expiry you set when creating it
OAuth 2.1Authorization: Bearer ado_at_...Access token 24 hours; the client refreshes it automatically

OAuth 2.1 (MCP connectors)

AgentDocs runs a built-in OAuth 2.1 authorization server (RFC 8414 discovery, dynamic client registration, PKCE). You never copy a token — the whole flow is four steps:

  1. In Claude, open Settings → Connectors → Add custom connector and enter https://agentdocs.eu/mcp
  2. Leave Advanced settings empty — no OAuth Client ID, no secret, no headers.
  3. Your browser opens the AgentDocs consent page: sign in and click Approve.
  4. Done — Claude holds a documents-only credential you can revoke any time under Settings → Connected apps.

ℹ️ Troubleshooting: If an older connector shows "Connection issue" or "server isn't responding", remove it and add it again. The first connection can time out once while the database wakes up; retry it. A grant covers your documents only, never account, billing or credential management, and is revoked when you change or reset your password.

Share links (no auth)

Share links give read-only access to one page with no authentication at all. The token in the URL is the credential:

# No Authorization header
curl https://agentdocs.eu/api/shared/SHARE_TOKEN/raw

# Returns plain Markdown with YAML frontmatter

This is the simplest way to give an AI agent access to documentation. See the Working with agents guide for detailed examples.

Error responses

A failed request returns a status code and a JSON body. Its error field says what went wrong:

StatusMeaningCommon cause
401 UnauthorizedMissing or invalid credentialsNo Authorization header, an unknown or rotated token, the wrong scheme (Bearer with an API token), an expired JWT or space token, or a session ended by a password change. The error field names the case.
403 ForbiddenNot allowedThe credential is valid but cannot do this: your role in the space is too low, a space token is used outside its space or beyond its permission, an OAuth grant is used outside your documents, or the workspace hit a plan limit.
404 Not FoundResource not foundWrong ID, the item is in the trash, or the share link was revoked or has expired.
# 401: no Authorization header (abridged: the body also lists the
# accepted header formats and where to get a token)
{
  "error": "authentication_required",
  "message": "AgentDocs treats AI agents as first-class API clients. This endpoint is private — authenticate to use it, or read pages shared via a public magic link without any credential.",
  "docs": "https://agentdocs.eu/llms.txt"
}

# 401: unknown, rotated or revoked API token (abridged)
{
  "error": "invalid_token",
  "message": "API token not recognized. It may have been rotated or revoked."
}

# 403: a read-only space token tried to write
{
  "error": "token_permission_denied",
  "message": "This token permits reading only."
}

Security best practices

Never commit tokens to version control. Keep them in environment variables or a secret manager.

Give an agent the least access it needs: a share link to read one page, a Read only space token to read one space, or a Read and propose edits token so a person approves every change.

An account API token can do everything your account can, in every workspace. For an agent that works in one space, create a space-scoped token instead, and give it an expiry date.

If a token leaks, replace it. For the account token, use Profile → Regenerate API Token (this needs a signed-in browser session). For a space token, revoke it in the space's token list. A password reset also replaces your account token.

Give share links an expiry when you create them, and revoke them when they are no longer needed.

Important: Treat your API token like a password. Anyone who has it can read and change everything your account can reach. Deleting the account and regenerating the token still need a signed-in browser session.

Rate limits and monthly quotas

Each workspace has a monthly API-call quota that depends on its plan. The count resets on the 1st of each month (UTC).

Free

10,000

API calls / month

Pro

1,000,000

API calls / month

Every request that targets a workspace's content counts, including the web app's own and real-time saves. Sign-in, account, billing and slug-resolve requests do not. Once the quota is used up, requests made with an API token, a space token or OAuth get 403 with error "Tier limit reached"; the body also gives limit, current and tier. Signed-in browser sessions keep working. Until the owner verifies their email address, a free workspace gets 1,000 calls a month.

Short-term limits apply separately and return 429 Too Many Requests: 300 requests per 15 minutes per credential, 1,200 per 15 minutes per IP address, and 15 per 15 minutes per IP address for sign-in and registration. The RateLimit-* response headers show how much of the per-credential limit is left.

AgentDocs v1.1.0 · b55b6f7