PDF4.dev
Learn

Authentication

The REST API supports two authentication methods depending on the context. The MCP server for AI assistants also accepts an OAuth sign-in, covered at the end of this page.

API key authentication

For external API calls (from your backend, scripts, CI/CD), use a Bearer token in the Authorization header:

Authorization: Bearer p4_live_xxx...

Creating an API key

  1. Go to API keys
  2. Click Create API key
  3. Copy the full token immediately (it's only shown once)

Keys always start with the p4_live_ prefix.

Permission scopes

ScopeAccess
full_accessAll endpoints: render, templates CRUD, logs, stats
render_onlyOnly POST /api/v1/render

Use render_only keys in environments where you only need to generate PDFs, like a backend service. Use full_access for admin scripts that also manage templates.

Security

  • API keys are hashed with SHA-256 before storage. We never store the plain token.
  • Deleting a key immediately revokes it. Any requests using that key will fail.
  • Rotate keys regularly and never commit them to version control.

Session authentication

The dashboard uses cookie-based sessions managed by better-auth. Session auth is used for:

  • All dashboard pages
  • POST /api/v1/render/preview (live preview in the editor)
  • API key management endpoints
  • Account deletion

Session auth is not available for external API calls. Use API keys instead.

MCP server (AI assistants)

The MCP server at https://pdf4.dev/api/mcp accepts two credentials, both checked before any tool runs:

  • OAuth sign-in: Claude (claude.ai, Claude Desktop, Claude mobile), Claude Code and ChatGPT sign you in to PDF4.dev, with no API key. The consent screen grants Full access (pdf4:full) or Render only (pdf4:render) for one organization. See Connect with OAuth.
  • API key: the same Authorization: Bearer p4_live_... header as the REST API, for Cursor, VS Code, Windsurf, Codex CLI, Gemini CLI, scripts and CI.

OAuth sign-in applies to the MCP server only. REST calls to /api/v1/* always use an API key.

Error responses

Invalid or missing authentication returns a 401 with a structured error:

401 Unauthorized
{
  "error": {
    "type": "authentication_error",
    "code": "unauthorized",
    "message": "Unauthorized"
  }
}

Using a render_only key on a full_access endpoint (templates, components and logs) returns a 403, not a 401: the key is valid, it lacks the scope.

403 Forbidden
{
  "error": {
    "type": "authentication_error",
    "code": "insufficient_permissions",
    "message": "Your API key does not have the required permissions for this endpoint."
  }
}

The MCP server answers the same case inside the tool result, with "type": "permission_error" and "code": "insufficient_permission".