Authentication & Scopes

How Postkub scoped API keys authenticate requests, the canonical scopes table, key lifecycle rules, and security practices.

Updated

Open in ClaudeOpen in ChatGPT
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), or prd (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 prefix shown in key listings and GET /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:

  1. Brands (brandIds): 1–50 Brand IDs belonging to the workspace.
  2. Social accounts (accountIds): 1–50 connected account IDs, each belonging to one of the selected Brands.
  3. 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.

ScopeWhat it allowsNotes
brand:readList authorized Brands (GET /api/v1/brands) and include Brand details in GET /api/v1/meRequired to see brands objects in /api/v1/me; brandIds are always returned
account:readList 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:scheduleUpdate weekly queue slots and IANA timezone (PATCH /api/v1/accounts/{id}/schedule-settings)Does not manage OAuth connections or account credentials
post:createCreate new drafts (POST /api/v1/posts) for authorized Brands and accountsExternal keys must specify at least one target account
post:readList and read posts (GET /api/v1/posts, GET /api/v1/posts/{id}) within key scopeReturns full or partial projection depending on target coverage
post:updateEdit drafts (PATCH /api/v1/posts/{id})Allowed only while status is draft and requires full target scope
post:publishPublish 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:scheduleSchedule 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:cancelCancel unstarted targets or request reconciliation for in-flight targets (POST /api/v1/posts/{id}/cancel)Never deletes an already-published remote post
post:deleteDelete 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:readList 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:replySubmit durable replies to comments (POST /api/v1/comments/{id}/replies)Subject to per-account provider reply capability
thread:updateUpdate thread unread state (PATCH /api/v1/threads/{id})Local inbox triage state
thread:resolveMark threads handled or reopen them (PATCH /api/v1/threads/{id})Local inbox resolution state
insight:readRead 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:readList 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, and actions. If the key lacks brand:read, brands is null; if it lacks account:read, accounts is null.
  • 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 actions array returns HTTP 403 PERMISSION_DENIED.
  • Requesting a single resource (such as an account, post, or thread) outside your key's Brands or accounts returns HTTP 404 NOT_FOUND so 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 brandId or accountId returns an empty items array.
  • 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/* returns 403 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. Once expiresAt passes, every new call fails with HTTP 401 KEY_EXPIRED.
  • Scope edits: Owners can rename a key, update its brandIds, accountIds, actions, or expiresAt. Each edit increments the key's revision. A key's environment cannot 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_REVOKED and 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/*:

HTTPCodeCause
400AMBIGUOUS_CREDENTIALSBoth a session cookie and an Authorization header were sent
401INVALID_TOKENMissing, malformed, or unrecognized Bearer API key
401KEY_REVOKEDAPI key has been revoked or rotated out
401KEY_EXPIREDAPI key passed its expiresAt timestamp
403KEY_LANE_FORBIDDENAPI key attempted an owner-only or web media-gateway endpoint
403PERMISSION_DENIEDKey lacks the required action grant or full target scope
403LEGACY_KEY_UNSUPPORTEDSuperseded legacy agent key presented on /api/v1/*
403ACCOUNT_SUSPENDEDWorkspace owner account is suspended
429KEY_ADMISSION_LIMITEDToo many failed key verification attempts (30/min per IP or 10/min per prefix); retry after details.retryAfterMs
429RATE_LIMITEDPer-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_KEY from your runtime environment or a protected user config file (mode 0600) 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, and production keys 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.