Guide
Authentication and credentials
How bearer tokens, browser sessions, permissions and origin checks differ, and how to handle secrets safely.
Two surfaces, two authentication models
api.datapi.ir is the public machine API. Send a workspace bearer token created in the dashboard. app.datapi.ir/api/v1 is the browser surface; the dashboard sends an HttpOnly session cookie automatically and the Next.js BFF forwards it. A browser session cookie is never accepted as a machine credential, and a machine token should never be embedded in browser code.
Which header to use
| Surface | Header | When it is used |
|---|---|---|
| Machine API | Authorization: Bearer <token> | Server-to-server requests to api.datapi.ir |
| Browser API | Cookie: datapi_session=… | Same-origin dashboard calls; set by OTP verification |
| OTP start/verify | No credential | Public browser endpoints, still origin-checked on mutation |
Rules that prevent most integration failures
- Store the secret once, in a secret manager. The dashboard cannot display it again after creation.
- Scope credentials to one workspace. Requests are always evaluated against that workspace, never a client-supplied workspace ID.
- Revoke a credential immediately if it leaks. Revocation is effective for new requests without a redeploy.
- The session cookie is `datapi_session`: HttpOnly, SameSite=Lax and Path=/, with the Secure flag set wherever the deployment serves HTTPS. Browser code cannot read it, so do not try to copy the cookie into a script.
- Expect 401 for missing, expired or revoked credentials and 403 for a missing/forbidden browser origin or insufficient permission.
Never expose provider details
Never expose provider details: DataPI credentials are not upstream provider credentials. Do not expect or send source-specific account IDs, API keys or actor identifiers; the public contract deliberately omits them.
Related pages
- Quickstart: from token to verified resultCreate a workspace token, inspect an operation, submit an asynchronous request and read the result.
- Machine API versus browser session APIWhich endpoints are public contracts, which are dashboard-only, and how the Next.js BFF forwards the session cookie.
- Usage, limits and retentionWhat each monthly plan includes, which technical limits apply, and which limits are operation-specific rather than global promises.