Hosted media

Attach publicly accessible HTTPS media URLs to posts via REST, CLI, and MCP, including URL validation rules and limits.

Updated

Open in ClaudeOpen in ChatGPT
On this page

Postkub uses a split media model designed for both teams and external automation: humans upload files through the web dashboard, while external REST, CLI, and MCP clients attach publicly accessible, direct-download HTTPS URLs via mediaUrls. Postkub does not transfer media bytes from the caller's machine.

Note

The REST API is available now. Equivalent postkub CLI examples below reflect the @postkub/cli preview client, which is not yet published to npm.

Human uploads vs external hosted URLs

WorkflowCallerHow media is attached
Web dashboardSigned-in human sessionBrowser uploads files to Postkub's session-only media gateway (/api/v1/media/*), producing mediaAssetIds
External automationREST API, CLI, or MCP with a scoped API keyHost media on public HTTPS storage (S3, Cloudflare R2, GCS, or a CDN) and pass direct URLs in mediaUrls

Calling /api/v1/media/* with an API key is always rejected with HTTP 403 KEY_LANE_FORBIDDEN. Neither the CLI nor the MCP server uploads local files or reads your local filesystem for media transfer.

Attach hosted media to a draft

Pass an ordered array of direct HTTPS links in mediaUrls when creating a draft (POST /api/v1/posts):

curl -sS -X POST https://postkub.com/api/v1/posts \
  -H "Authorization: Bearer <API_KEY>" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 11111111-1111-4111-8111-111111111111" \
  -d '{
    "brandId": "brand_example01",
    "socialAccountIds": ["acc_example01"],
    "text": "Weekend tasting flight is ready.",
    "mediaUrls": [
      "https://cdn.example.com/campaigns/roast-01.jpg",
      "https://cdn.example.com/campaigns/roast-02.jpg"
    ]
  }'

Equivalent CLI command using repeatable --media-url flags (preview):

postkub posts create \
  --brand-id brand_example01 \
  --account-id acc_example01 \
  --text "Weekend tasting flight is ready." \
  --media-url https://cdn.example.com/campaigns/roast-01.jpg \
  --media-url https://cdn.example.com/campaigns/roast-02.jpg \
  --output json

To replace or clear mediaUrls on a draft before publishing, send PATCH /api/v1/posts/{id} with expectedRevision:

  • Omit mediaUrls to keep the existing list unchanged.
  • Pass a new array to replace the ordered URL list.
  • Pass "mediaUrls": [] to remove all hosted URLs from the draft.

Postkub preserves the exact array order and binds mediaUrls into both the draft's SHA-256 content hash and the immutable publication envelope when you call /publish or /schedule.

Validation rules enforced by the API

Postkub validates every URL in mediaUrls at the request boundary (on both POST /api/v1/posts and PATCH /api/v1/posts/{id}). Invalid URLs fail immediately with HTTP 400, error.code: "VALIDATION_ERROR", and an error.message prefixed with INVALID_MEDIA_URL::

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "INVALID_MEDIA_URL: A direct public media URL is required; viewer and share pages are not supported",
    "details": {
      "mediaUrls": [
        "INVALID_MEDIA_URL: A direct public media URL is required; viewer and share pages are not supported"
      ]
    },
    "retryable": false
  },
  "requestId": "11111111-1111-4111-8111-111111111111"
}

URL and count rules

RuleRequirementRejected examples
SchemeMust use https://http://cdn.example.com/a.jpg, file:///tmp/a.jpg
Length and whitespaceNon-empty, at most 2,048 characters, no whitespaceURLs containing spaces or longer than 2,048 chars
CredentialsNo embedded username or passwordhttps://user:pass@cdn.example.com/a.jpg
Public host (SSRF guard)Must be a public hostname or globally routable IPlocalhost, *.local, *.internal, *.localhost, *.test, *.invalid, single-label hosts, private/reserved IPv4 (10.0.0.0/8, 127.0.0.0/8, 169.254.0.0/16, 172.16.0.0/12, 192.168.0.0/16, 100.64.0.0/10, 0.0.0.0/8, >= 224.0.0.0), non-global IPv6 (::1, fc00::/7, fe80::/10, 2001:db8::/32, 2002::/16, IPv4-mapped/NAT64 private ranges)
Direct file URL (no viewer pages)Must point directly to raw media bytes, not an HTML share pagehttps://drive.google.com/file/d/.../view, https://drive.google.com/open?..., https://docs.google.com/..., https://1drv.ms/..., https://onedrive.live.com/..., https://www.dropbox.com/s/... without ?raw=1 or ?dl=1
URL countAt most 10 URLs in mediaUrls per post11 or more URLs in mediaUrls
DuplicatesEvery URL must be unique after normalization and stripping #fragmenthttps://cdn.example.com/a.jpg and https://cdn.example.com/a.jpg#1 in the same array

Platform item-count limits

In addition to the 10-URL cap on mediaUrls, Postkub checks per-platform image item limits against every target account on the post. Exceeding a target platform's count returns HTTP 422 IMAGE_COUNT_EXCEEDS_PLATFORM_LIMIT, and attaching images to a video-only platform (such as YouTube) returns HTTP 422 IMAGE_UNSUPPORTED_FOR_PLATFORM.

For hosted image URLs, the effective ceiling is the smaller of 10 (mediaUrls limit) and the strictest target platform's image limit (for example, 4 items when targeting X, 10 for Facebook or Instagram, 0 for YouTube).

Keep URLs publicly readable until publication finishes

Postkub validates URL syntax and host safety when you save a draft, but it does not download or probe your hosted URLs during draft creation, and it cannot verify byte sizes of hosted URLs ahead of time.

Follow these hosting rules so scheduled publications do not fail later:

  • Serve raw media bytes without login: The URL must respond directly with the media content (not an HTML preview page, sign-in redirect, or cookie wall).
  • Keep the URL reachable past the scheduled time: For scheduled posts, the social platform or worker fetches the URL at fireAtUtc and may continue reading it during asynchronous processing or safe retries. If you use signed object-storage URLs (such as S3 or R2 pre-signed URLs), set their expiration well beyond the scheduled publish time—or serve assets from a public bucket/CDN path until status reaches published.
  • Match target platform format and size rules: Because Postkub cannot inspect or resize external URLs at draft time, ensure your hosted images meet each destination network's resolution, aspect-ratio, and file-size requirements before publishing.

Declaring mediaKind for video URLs

Posts with mediaUrls default to mediaKind: "image". Postkub never infers video from a .mp4 or .mov file extension.

  • To declare a hosted video draft, pass "mediaKind": "video" explicitly (CLI: --media-kind video).
  • A video post must contain exactly one media item; sending zero or multiple items with "mediaKind": "video" is rejected with MEDIA_SHAPE_UNSUPPORTED.

Warning

Planned / account-dependent video support: Live video and Reel publication availability depends on per-account provider qualification and is not enabled for every connected platform. Always inspect publishFormats in GET /api/v1/accounts/{id}/capabilities before publishing or scheduling a video post—unqualified formats are rejected at acceptance with 422 MEDIA_SHAPE_UNSUPPORTED or 422 PROVIDER_CAPABILITY_UNAVAILABLE.

  • Your First Post — end-to-end draft, publish, schedule, cancel, and retry tutorial.
  • Scheduling — explicit schedules, weekly queue slots, and timezone behavior.
  • API Reference: Posts — full request schema for mediaUrls, mediaKind, and draft updates.
  • Errors — error envelope and status codes.