Quickstart & MCP Guide
PostForAI exposes a stateless REST API under /v1/* and a Streamable HTTP MCP 2025-11-25 server at /mcp. Follow these six steps to authenticate, send a sandbox post, connect Claude or Cursor, upload media, and verify signed webhooks.
1. Authentication & environments
Create workspace API keys in Console › API & MCP. Every key belongs to one workspace and one environment:
sp_live_…publishes to real connected social accounts.sp_test_…runs in sandbox mode against virtual test accounts (test_x:demo,test_instagram:qa) without calling upstream social APIs.
Send your key in X-API-Key or Authorization: Bearer. Keys are rate-limited to 120 requests per minute.
2. Send your first post in 60 seconds
curl -X POST https://postforai.com/v1/posts \
-H "X-API-Key: sp_test_replace_me" \
-H "Idempotency-Key: hello-world-001" \
-H "Content-Type: application/json" \
-d '{
"caption": "Hello from PostForAI sandbox!",
"social_accounts": ["test_x:demo", "test_bluesky:demo"]
}'
Every scheduled timestamp must use strict UTC ISO-8601 with an explicit offset or Z (for example 2026-12-01T15:00:00Z). Naive local datetimes return HTTP 400.
3. Connect AI assistants via MCP 2025-11-25
PostForAI serves Streamable HTTP MCP (2025-11-25) at https://postforai.com/mcp with two authentication methods:
- OAuth 2.1 (Claude, ChatGPT, MCP Inspector): Enter
https://postforai.com/mcpas the server URL. Your client discovers/.well-known/oauth-protected-resource, registers automatically via DCR, signs in with PKCE S256, and opens the workspace consent page. - API Key (Cursor, Claude Code, CI agents): Send
X-API-KeyorAuthorization: Bearer sp_live_…directly toPOST /mcp.
All 25 tools enforce workspace permissions. Creating a post requires idempotency_key, and all 5 destructive tools require confirm: true.
4. Connect social accounts (B2B & BYO OAuth)
Call POST /v1/social-accounts/auth-url with a platform and optional HTTPS redirect_url to generate a single-use OAuth link for your user. PostForAI handles token exchange at /oauth/{platform}/callback, encrypts tokens with AES-256-GCM, and redirects back to your app.
X (Twitter) requires your own OAuth 2.0 Client ID and Secret via PUT /v1/oauth-apps/x or Console › Accounts. Discord, Telegram, and Bluesky connect directly via credentials.
5. Upload images and videos (R2)
- Up to 100 MB: Send raw binary bytes to
PUT /v1/mediawithContent-TypeandContent-Length. Magic bytes are validated while streaming. - 100 MB to 4 GB: Request a presigned S3 PUT URL via
POST /v1/media/upload-url, upload directly to Cloudflare R2, and finalize withPOST /v1/media/{id}/confirm.
6. Verify webhook signatures (HMAC-SHA256)
Every webhook includes X-PostForAI-Signature (t=<ts>,v1=<hmac>) and X-PostForAI-Event. Verify using constant-time comparison against the raw request body:
import crypto from 'node:crypto';
function verifyPostForAISignature(rawBody, signatureHeader, secret) {
// Header format: t=<unix_seconds>,v1=<hex_hmac_sha256>
const parts = Object.fromEntries(signatureHeader.split(',').map((p) => p.split('=')));
const expected = crypto
.createHmac('sha256', secret)
.update(`${parts.t}.${rawBody}`)
.digest('hex');
return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1 ?? ''));
}