Authentication & Scopes
How Postkub scoped API keys authenticate requests, the canonical scopes table, key lifecycle rules, and security practices.
Updated
On this page
External REST, CLI, and MCP clients authenticate with scoped Postkub API keys issued by a workspace owner in API Settings. Every key is bound to explicit Brands, connected social accounts, and social action grants—never to an AI agent profile or owner administration.
How API key authentication works
Send your API key in the Authorization HTTP header using the Bearer scheme:
Authorization: Bearer <API_KEY>
Example request:
curl -sS https://postkub.com/api/v1/me \
-H "Authorization: Bearer <API_KEY>"
API keys follow the format pk_<env>_<secret>:
<env>identifies the environment chosen at creation:dev(development),stg(staging), orprd(production).<secret>is a random URL-safe string (32–128 characters; total token length up to 256 characters).- The first 12 characters form the lookup
prefixshown in key listings andGET /api/v1/me(for example,pk_prd_ab12c).
Postkub shows the full plaintext key once at creation or rotation, stores only a salted scrypt hash, and verifies secrets in constant time.
Warning
Never send a browser session cookie and an Authorization header on the same /api/v1/* request. Postkub rejects mixed credentials immediately with HTTP 400 AMBIGUOUS_CREDENTIALS.
How scoping works
Every API key defines three explicit boundaries, and all three must match for a request to succeed:
- Brands (
brandIds): 1–50 Brand IDs belonging to the workspace. - Social accounts (
accountIds): 1–50 connected account IDs, each belonging to one of the selected Brands. - Actions (
actions): One or more grantable social action strings from the table below.
Selecting a Brand does not automatically grant access to every social account in that Brand, and connecting a new account later does not automatically add it to existing keys. To include a new account, the owner updates the key in API Settings.
When a post targets multiple social accounts across the same Brand:
- Reads (
GET /api/v1/posts,GET /api/v1/posts/{id}): If your key can access the Brand and at least one target account, you see the post. If your key does not cover every target on that post, Postkub returns a partial projection containing only your authorized targets. - Whole-post writes (
PATCH /api/v1/posts/{id},DELETE /api/v1/posts/{id},POST /api/v1/posts/{id}/archive): Require authority over every target account on the post. - Target-specific publication actions (
/publish,/schedule,/cancel,/retry): Require authority over every account you explicitly select in the request.
Canonical scopes table
Every grantable external API key action is listed below. Any action omitted from a key is denied by default.
| Scope | What it allows | Notes |
|---|---|---|
brand:read | List authorized Brands (GET /api/v1/brands) and include Brand details in GET /api/v1/me | Required to see brands objects in /api/v1/me; brandIds are always returned |
account:read | List authorized accounts (GET /api/v1/accounts), read capabilities (GET /api/v1/accounts/{id}/capabilities), and read weekly queue settings (GET /api/v1/accounts/{id}/schedule-settings) | Required to see accounts objects in /api/v1/me; accountIds are always returned |
account:schedule | Update weekly queue slots and IANA timezone (PATCH /api/v1/accounts/{id}/schedule-settings) | Does not manage OAuth connections or account credentials |
post:create | Create new drafts (POST /api/v1/posts) for authorized Brands and accounts | External keys must specify at least one target account |
post:read | List and read posts (GET /api/v1/posts, GET /api/v1/posts/{id}) within key scope | Returns full or partial projection depending on target coverage |
post:update | Edit drafts (PATCH /api/v1/posts/{id}) | Allowed only while status is draft and requires full target scope |
post:publish | Publish now (POST /api/v1/posts/{id}/publish) and retry failed publish-now targets (POST /api/v1/posts/{id}/retry) | Also required alongside post:schedule for scheduling and scheduled retries |
post:schedule | Schedule posts (POST /api/v1/posts/{id}/schedule) and retry failed scheduled targets (POST /api/v1/posts/{id}/retry) | Always requires post:publish as well |
post:cancel | Cancel unstarted targets or request reconciliation for in-flight targets (POST /api/v1/posts/{id}/cancel) | Never deletes an already-published remote post |
post:delete | Delete unaccepted local drafts (DELETE /api/v1/posts/{id}) and archive finished posts (POST /api/v1/posts/{id}/archive) | Requires full target scope; never deletes remote social posts |
comment:read | List inbox threads, post buckets, and comments, and read thread/reply status (GET /api/v1/threads, /threads/{id}, /inbox/posts, /comments, /replies/{id}) | Read-only inbox access |
comment:reply | Submit durable replies to comments (POST /api/v1/comments/{id}/replies) | Subject to per-account provider reply capability |
thread:update | Update thread unread state (PATCH /api/v1/threads/{id}) | Local inbox triage state |
thread:resolve | Mark threads handled or reopen them (PATCH /api/v1/threads/{id}) | Local inbox resolution state |
insight:read | Read saved account and post metrics, batch insights, and metric series (GET /api/v1/accounts/{id}/insights, /posts/{id}/insights, /insights/*) | Read-only saved snapshots with freshness metadata |
activity:read | List scoped social activity and sanitized failure logs (GET /api/v1/activity) | Filtered strictly to authorized Brands and accounts |
Endpoints that need no extra discovery grant
GET /api/v1/me: Any valid, active API key can inspect its own identity, workspace,brandIds,accountIds, andactions. If the key lacksbrand:read,brandsisnull; if it lacksaccount:read,accountsisnull.GET /api/v1/requests/{requestId}: Recovers durable mutation receipts created by the same API key only (principal-namespaced) and re-checks current authority before returning stored data. See Idempotency & Request Recovery.
Note
Legacy media upload actions (media:write, media:read, media:delete) cannot be granted to new keys. External API keys attach media via Hosted Media (mediaUrls) instead of the session-only media upload gateway.
The all-social-actions preset
When you create a new key in API Settings, Postkub pre-selects all currently supported social actions—the 16 actions in the canonical table above.
Keep three boundaries in mind:
- Target-restricted: The preset applies only to the specific Brands and social accounts you select on that key.
- Point-in-time snapshot: It saves today's supported social action list. When Postkub ships new social actions in the future, existing keys do not receive them automatically—an owner must explicitly edit the key to add new grants.
- No administration: The preset never includes owner administration, OAuth management, key management, or billing.
Default deny
Postkub enforces default deny on every endpoint:
- Calling an endpoint whose required action is not in the key's
actionsarray returns HTTP403 PERMISSION_DENIED. - Requesting a single resource (such as an account, post, or thread) outside your key's Brands or accounts returns HTTP
404 NOT_FOUNDso unauthorized keys cannot probe whether unrelated records exist. - List endpoints return only items inside your key's current scope; filtering by an out-of-scope
brandIdoraccountIdreturns an emptyitemsarray. - Authorized social requests execute or schedule directly—Postkub does not impose an approval queue, per-key posting quota, allowed-hours window, or keyword rule on top of granted scopes.
What API keys can never do
Owner administration requires a signed-in human web session. Sending any Authorization header to an owner administration endpoint returns HTTP 403 KEY_LANE_FORBIDDEN, even if a session cookie is also present.
External API keys can never:
- Create, rename, or delete Brands
- Connect, reconnect, or disconnect social accounts via OAuth
- Create, edit, rotate, or revoke API keys
- Configure webhook endpoints or replay webhook deliveries
- Manage billing, subscriptions, or workspace deletion requests
- Upload media bytes through the web media gateway (
/api/v1/media/*returns403 KEY_LANE_FORBIDDEN) - Create targetless Brand drafts (
403 TARGETLESS_DRAFT_OWNER_ONLY) or like comments (403 ACTION_NOT_AVAILABLE_FOR_KEYS)
Expiry, editing, rotation, and revocation
Workspace owners manage the full key lifecycle in API Settings:
- Expiry: Keys can have no expiration (
expiresAt: null) or a future UTC expiration timestamp. OnceexpiresAtpasses, every new call fails with HTTP401 KEY_EXPIRED. - Scope edits: Owners can rename a key, update its
brandIds,accountIds,actions, orexpiresAt. Each edit increments the key'srevision. A key'senvironmentcannot be changed, and revoked keys cannot be edited. - Rotation: Rotating an active, non-expired key atomically revokes the old key and issues a replacement with the same label, environment, Brands, accounts, actions, and
expiresAt(after verifying every granted Brand and account is still valid). The replacement gets a fresh one-time secret and starts a fresh per-key rate-limit window. Revoked or expired keys cannot be rotated. - Revocation: Revoking a key immediately blocks all new API calls with HTTP
401 KEY_REVOKEDand prevents replaying prior idempotency receipts with that key.
Warning
Accepted schedules continue after revocation. When Postkub accepts a publish or schedule request, it stores immutable publication intent along with the source key ID and scope snapshot. Revoking, expiring, or narrowing a key stops new API calls only—it does not pause or cancel posts already queued for publication. To stop a scheduled post, cancel it explicitly through POST /api/v1/posts/{id}/cancel or in the web dashboard.
Authentication errors
Common authentication and admission responses on /api/v1/*:
| HTTP | Code | Cause |
|---|---|---|
400 | AMBIGUOUS_CREDENTIALS | Both a session cookie and an Authorization header were sent |
401 | INVALID_TOKEN | Missing, malformed, or unrecognized Bearer API key |
401 | KEY_REVOKED | API key has been revoked or rotated out |
401 | KEY_EXPIRED | API key passed its expiresAt timestamp |
403 | KEY_LANE_FORBIDDEN | API key attempted an owner-only or web media-gateway endpoint |
403 | PERMISSION_DENIED | Key lacks the required action grant or full target scope |
403 | LEGACY_KEY_UNSUPPORTED | Superseded legacy agent key presented on /api/v1/* |
403 | ACCOUNT_SUSPENDED | Workspace owner account is suspended |
429 | KEY_ADMISSION_LIMITED | Too many failed key verification attempts (30/min per IP or 10/min per prefix); retry after details.retryAfterMs |
429 | RATE_LIMITED | Per-key requests-per-minute limit exceeded; retry after details.retryAfterMs |
See Errors for the complete error catalog and Rate Limits for admission limits and headers.
Key-safety rules
- Use environment variables or a secret manager: Supply
POSTKUB_API_KEYfrom your runtime environment or a protected user config file (mode0600) outside your git repository. - Never expose secrets in arguments or logs: Do not pass keys as CLI positional arguments, embed them in URLs, commit them to repository files, or print them to stdout/logs.
- Use HTTPS everywhere: Never send API keys over plaintext HTTP outside local development.
- Follow least privilege: Grant only the Brands, accounts, and actions each automation needs, and separate
development,staging, andproductionkeys so a leak in one environment is isolated and easy to trace by prefix. - Rotate on schedule or after exposure: Rotate immediately in API Settings if a secret may have been logged or leaked, and cancel any unwanted queued posts separately.
