Skip to content

Authentication

Every request to the Pagr API is authenticated with a bearer API key. There is no OAuth flow, no token exchange, and no refresh step — the key is a long-lived credential you send on each request.

You generate keys in the workspace under Settings → API Keys. See API Keys for the full walkthrough, including the difference between test and production keys and how to rotate a key that’s been exposed.

Send your key as a bearer token in the Authorization header:

Authorization: Bearer pagr_prod_xxxxxxxxxxxxxxxx

That’s the only credential a request needs. No other header carries authentication, and there’s no session or cookie to maintain. Every official SDK attaches it for you — you pass the key when constructing the client.

The two service probes (GET /v1/meta/status and GET /v1/meta/version) are the only anonymous endpoints, so an uptime monitor or autoscaler can call them without a credential. Everything else requires the header.

The key’s prefix decides which environment the request runs in — you never pass a separate flag:

Test (pagr_test_*) Production (pagr_prod_*)
Output Watermarked Full, unwatermarked
Page credit Not consumed Consumed
Batch cap 10 documents per request No fixed cap
Blocks rendering on Error issues only Warning and Error issues

Switching environments is just a matter of switching keys — including at runtime, via set_api_key on a live client.

Your API key grants the ability to render documents and read your organisation’s data, so treat it like a password:

Rotation doesn’t require a restart: every SDK exposes set_api_key (or its language equivalent) to swap the key on a live client without tearing down its connection pool. Be aware that swapping a pagr_test_ key for a pagr_prod_ one silently switches every subsequent render to real, credit-consuming output — see Configure the client.

Two different authentication-related errors mean two different things:

  • 401 Unauthorized — the key is missing, malformed, or invalid. The request wasn’t authenticated at all. Check that the Authorization header is present and the key is correct. A distinct NotAuthenticated code means the key is well-formed but has no associated organisation.
  • 403 Forbidden — the key is valid and the request was authenticated, but the authenticated organisation isn’t allowed to perform this action. A new key won’t fix this — the permission is the issue.

See Errors for every other status code the API returns, and Handle errors and retries for the exception each maps to in the SDKs.

  • API Overview — base URL, rendering shapes, and errors.
  • Configure the client — where the key goes, and how to rotate it.
  • Errors — the full status code reference.
  • API Keys — generate, rotate, and manage keys.
  • Webhooks — note that callbacks carry no auth header, and how to secure your endpoint anyway.
  • SDKs — client libraries that handle the header for you.