API Bearer Token Authentication, Headers, and Token Lifecycle
How HTTP Bearer authorization works on REST APIs, including token create and revoke, variant headers, and common auth mistakes.
Most of the material here comes from Perplexity HTTP API reference and admin docs: almost every endpoint expects credentials in an Authorization header. A smaller set of Cloudflare pages shows the same Bearer pattern, proxy-specific headers, public endpoints with no auth, and traps when the wrong credential format is used.
Authorization header: what Bearer means on API requests
Section titled “Authorization header: what Bearer means on API requests”API clients prove identity by sending a secret or key on each request. On Perplexity’s documented REST surface, the scheme is HTTP Bearer: a required header whose value is the word Bearer, a space, and your token.
Bearer authentication header of the form
Bearer <token>, where<token>is your auth token.— Perplexity, Search the Web
The same wording appears on agent, batch, file, skill, embedding, and legacy Sonar routes (for example Create Agent Response, Create a batch, Create Embeddings). Gateway routes describe the credential the same way in practice but label it explicitly as your API key in the reference (Create Chat Completion (gateway), List Models).
Perplexity Orchestrator and routed responses use the same rule:
Requests authenticate with an
Authorization: Bearerheader, which the SDKs set for you from theapi_keyparameter.— Perplexity, Perplexity Orchestrator API
Typical raw HTTP shape:
curl https://api.perplexity.ai/<path> \ -H "Authorization: Bearer $PERPLEXITY_API_KEY" \ -H "Content-Type: application/json"How Perplexity differs from Cloudflare’s global API pattern
Section titled “How Perplexity differs from Cloudflare’s global API pattern”Cloudflare’s API troubleshooting documents a frequent mistake: using API key syntax (email plus global API key) when the product expects a Bearer API token:
Occasionally customers will attempt to use an API token with an API key syntax. Ensure you are using the Bearer option rather than the email and API key pair.
— Cloudflare, Troubleshooting
Perplexity’s reference in this cluster does not describe an email/key pair; it standardizes on Bearer <token>. If you integrate both vendors, keep two mental models: Perplexity’s single header token, and Cloudflare’s requirement to pick the credential type the specific API documents.
Token lifecycle: generate, use, and revoke (Perplexity)
Section titled “Token lifecycle: generate, use, and revoke (Perplexity)”Some organizations rotate keys through Perplexity’s token APIs instead of only pasting a static key from a dashboard.
Generate Auth Token
Section titled “Generate Auth Token”Generate Auth Token is a POST that itself requires an existing Authorization: Bearer <token> header. A successful 200 returns JSON including:
auth_token— the new secret (example formpplx-1234567890abcdef)created_at_epoch_seconds— Unix creation timetoken_name— optional label
The newly generated authentication token. Store this securely as it cannot be retrieved again.
— Perplexity, Generate Auth Token
That cannot be retrieved again line is the operational rule: persist the value in your secret store immediately; there is no “show again” flow in this reference.
Revoke Auth Token
Section titled “Revoke Auth Token”Revoke Auth Token accepts POST to https://api.perplexity.ai/revoke_auth_token with JSON body auth_token set to the token to invalidate, plus Authorization: Bearer <token> on the caller. Success is 200 with message that the token was revoked.
Use revoke when a key leaks, an employee leaves, or you finish a rotation: generate the replacement, deploy it, then revoke the old auth_token value.
| Step | Action | Endpoint / field |
|---|---|---|
| Create | POST with Bearer auth |
Generate Auth Token → save auth_token |
| Use | Authorization: Bearer <auth_token> |
Any protected route, e.g. Search the Web |
| Retire | POST body { "auth_token": "..." } |
Revoke Auth Token |
Extra headers beyond Bearer
Section titled “Extra headers beyond Bearer”Bearer answers “who is calling.” Other headers in the cluster handle tracing, safety, proxies, or non-REST auth.
x-request-id (Perplexity Decisions and related APIs)
Section titled “x-request-id (Perplexity Decisions and related APIs)”Decisions API quickstart documents response tracing:
Responses carry an
x-request-idheader with a UUID, on success and on most errors. Log it with your results and quote it in support requests. A 401, a 404, and a 504 carry no request id.— Perplexity, Decisions API
Log the UUID on success paths; when support asks for a request id, know that 401, 404, and 504 responses may not include one.
Perplexity-Safety-Identifier (admin safety)
Section titled “Perplexity-Safety-Identifier (admin safety)”Safety Identifiers add an optional header for per-user policy without putting PII in the value:
Use an opaque ID, such as your internal user ID. Never send personal information. 1 to 64 printable ASCII characters, with no spaces or commas. Invalid values are ignored.
— Perplexity, Safety Identifiers
Example from the same page:
curl https://api.perplexity.ai/orchestrator/v1/responses \ -H "Authorization: Bearer $PERPLEXITY_API_KEY" \ -H "Content-Type: application/json" \ -H "Perplexity-Safety-Identifier: user_8f14e45f" \ -d '{"model": "perplexity/kimi-k3", "input": "Reply with OK."}'SDKs can attach it via extra_headers (Python) or the headers request option (TypeScript), per Safety Identifiers.
Proxy-Authorization (Cloudflare Privacy Proxy)
Section titled “Proxy-Authorization (Cloudflare Privacy Proxy)”Not every “authenticate this HTTP call” story uses Authorization. Cloudflare Privacy Proxy HTTP headers require proxy credentials:
Authenticates the client to the proxy. Required for all requests.
— Cloudflare, HTTP headers
Supported shapes include pre-shared key (Proxy-Authorization: Preshared <key>) and Privacy Pass (Proxy-Authorization: PrivateToken token=<base64-encoded-token>). Using a Bearer API token in Authorization on these routes would be the wrong header name and scheme.
Bearer on sandbox and MCP upstream (Cloudflare)
Section titled “Bearer on sandbox and MCP upstream (Cloudflare)”Cloudflare Sandbox HTTP API protects /v1/sandbox/* and /v1/openapi.* with:
Authorization: Bearer <SANDBOX_API_KEY>— Cloudflare, HTTP API reference
When SANDBOX_API_KEY is unset, auth is skipped for local development; production must set the secret. GET /health stays unauthenticated and returns {"ok": true}.
MCP server portals can forward a raw bearer token upstream (auth_type: "bearer") or a JSON string of custom headers for servers that need X-Api-Key and similar—still HTTP credential forwarding, but configured in portal metadata rather than typed by every client.
Endpoints with no Bearer (Cloudflare DNS over HTTPS)
Section titled “Endpoints with no Bearer (Cloudflare DNS over HTTPS)”Make API requests to 1.1.1.1 states:
No authentication is required to send requests to this API.
— Cloudflare, Make API requests to 1.1.1.1
Do not assume every Cloudflare HTTP API in the cluster needs Authorization; read the specific product page.
Non-Bearer application auth (Cloudflare SMTP)
Section titled “Non-Bearer application auth (Cloudflare SMTP)”Cloudflare Email Service SMTP uses AUTH PLAIN with a base64 payload, not Bearer:
AUTH PLAIN sends
\0api_token\0<API_TOKEN>encoded as base64— Cloudflare, SMTP
Same underlying API token idea, different wire format—relevant when debugging “works in curl but fails in SMTP.”
Invalid or expired tokens: what documentation says
Section titled “Invalid or expired tokens: what documentation says”When a JWT-style token is wrong or expired, Cloudflare RealtimeKit error codes give a concrete pattern (error code 1000):
Error message: Invalid auth token
Possible reason: The authentication token provided is invalid or malformed.
Possible solution: Ensure that the passed auth token is a valid JWT auth token that is not expired yet.— Cloudflare, Error Codes
For Perplexity, combine HTTP status with Decisions API guidance: log x-request-id when present; for 401 without a request id, fix Bearer formatting and token validity first.
Common mistakes when sending API keys
Section titled “Common mistakes when sending API keys”- Wrong scheme — Using Cloudflare email + global API key where Bearer API token is required (Troubleshooting).
- Wrong header name — Sending API credentials in
Authorizationto a proxy that expectsProxy-Authorization(HTTP headers). - Literal
Bearer <token>— Leaving angle-bracket placeholders in production scripts instead of the real secret (shown in Revoke Auth Token examples). - Assuming all routes need auth — Public DOH on 1.1.1.1 needs no header (Make API requests to 1.1.1.1); sandbox skips auth locally without
SANDBOX_API_KEY(HTTP API reference). - PII in safety headers — Safety Identifiers require opaque IDs; invalid values are silently ignored, which can break policy expectations.
- Losing generated tokens — Generate Auth Token does not let you fetch the same
auth_tokenagain after creation.
How to check this on your site
Section titled “How to check this on your site”-
Call a documented protected endpoint (for example Search the Web or List Models) with
Authorization: Bearerset to your real key and confirm you receive a success response, not401. -
Repeat once with a deliberately wrong token and confirm the API rejects the call; for Decisions-style APIs, note whether
x-request-idis absent on401as described in Decisions API. -
If you use Perplexity token rotation, run Generate Auth Token, deploy the new
auth_token, then Revoke Auth Token for the old value and confirm the old secret no longer works. -
For Cloudflare integrations, compare your client to Troubleshooting (Bearer token vs API key pair) and to the product-specific page (sandbox Bearer, proxy
Proxy-Authorization, or no auth on 1.1.1.1 DOH). -
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page does not match the official docs or your live API behavior, email yimasynthetic@gmail.com with the page URL and the exact sentence you think is wrong so it can be corrected or clarified.