# Media and threads

The parts of a draft beyond plain text: photos, videos and PDFs, X threads, polls, quotes and replies, LinkedIn link
cards and tags, and posts the owner makes by hand. This page is complete on its own. The bodies here go into
`createPost` or `createDraft` as they are; how to send and schedule the plan is in
[drafting](https://app.flaghand.com/docs/drafting.md).

The scheduler checks every choice here again right before posting.

## Upload media first

`uploadMedia` saves a file in the workspace's media library and answers a media item: its `id` (`med_…`), `kind`
(`image`, `video` or `document`), `type`, `size`, `alt`, `width`, `height` and `duration`. Then put its id in a body.

- Accepted: JPEG, PNG, WebP and GIF photos; MP4 and MOV videos; PDF documents; up to 50 MB. The file's first bytes
  must match the `Content-Type` you send, or it's refused (`unsupported_media_type`).
- **HTTP:** the raw bytes are the body, with the file's `Content-Type`; `alt`, `filename`, `width`, `height` and
  `duration` go in the query.

sh / Bash (workspace id in `WS`, token from secret storage):
```sh
printf 'Authorization: Bearer %s\n' "$FLAGHAND_TOKEN" | curl --header '@-' -s -X POST "https://app.flaghand.com/api/v1/workspaces/$WS/media?alt=Weekly%20views%2C%20up%2040%25&filename=chart.png" -H "Content-Type: image/png" -H "Idempotency-Key: $(uuidgen)" --data-binary '@chart.png'
```
PowerShell (`$env:WS`, `$env:FLAGHAND_TOKEN`):
```powershell
"Authorization: Bearer $env:FLAGHAND_TOKEN" | curl.exe --header '@-' -s -X POST "https://app.flaghand.com/api/v1/workspaces/$env:WS/media?alt=Weekly%20views%2C%20up%2040%25&filename=chart.png" -H "Content-Type: image/png" -H ("Idempotency-Key: " + [guid]::NewGuid().ToString()) --data-binary '@chart.png'
```

- **Remote MCP:** `uploadMedia` with `data_base64` (the file as standard base64, no `data:` prefix), `content_type`,
  `filename` and `alt`, plus `idempotency_key`. Sizes are digit strings there, such as `"width": "800"`. The base64 is
  your own output, so use it only for small files you write yourself. A file the person has goes through
  [Files](https://app.flaghand.com/docs/media-and-threads#where-a-file-can-come-from).
- **Local CLI or stdio MCP:** `flaghand media upload chart.png --alt "Weekly views, up 40%"`, or `file` with a readable
  path (relative to the process's working directory).

Width, height and a video's duration are read from the file itself. A value you send is used only where the file
doesn't give one (an animated WebP, an unusual video), and `0` is refused. `probeMedia` reads them again without
changing anything; `updateMedia` changes the default alt text.

Write real alt text: what the image shows, for someone who can't see it. A body's media reference can carry its own
`alt`; without one, the library's alt text is copied into the draft.

## Where a file can come from

| The file is | Route |
|---|---|
| On this machine, and you have the CLI or the local stdio MCP | `flaghand media upload PATH`, or `uploadMedia` with `file` |
| On this machine, and you have a shell and a token | `POST …/media` with the raw bytes and an `Idempotency-Key` |
| Already at a public URL | `media_from` on the body, or `importMedia` ([below](https://app.flaghand.com/docs/media-and-threads#media-from-a-page-or-file-url)) |
| Bytes you write yourself, over hosted MCP or WebMCP | `uploadMedia` with `data_base64`: small files only, never a video |
| Attached in this chat, or on the person's phone | The **Files** link: the person adds it |

A tool call can't carry a file the person attached in a chat: hosted MCP refuses `file`, and re-encoding a video as
`data_base64` makes it larger than the model can write. Give the person the Files link instead, with their workspace
id from `getMe` or `listWorkspaces`:

```text
https://app.flaghand.com/files?workspace=ws_…
```

It opens the app's Files screen in that workspace, after sign-in if they're signed out, and never another workspace.
They add the files from their phone or computer and watch each one finish. Nothing posts from Files, and the link
carries no token. A message to send with it:

```text
Open this link and add the videos there: https://app.flaghand.com/files?workspace=ws_…
Nothing posts from it. When they're done, tap Copy for your agent and paste it here.
```

**Copy for your agent** gives you plain text, one file per line: its `med_` id, file name and length.

```text
3 files in Flaghand workspace ws_…:
med_… IMG_0142.MOV 0:42
med_… IMG_0143.MOV 0:18
med_… IMG_0144.MOV 1:03
```

If they don't paste it, read `listMedia`: the newest 500 uploads, newest first, each with `filename`, `created_at`,
`created_by`, `kind`, `size`, `width`, `height` and `duration`. Name the files you picked in your plan's `note`; the
owner sees each real file on the schedule.

Files keeps the same limits as any upload: 50 MB a file, and 250 MB of stored media while starting without a card.

## Previews of files and posts

Two different things:

- **A post**, with its media in place, is the draft preview. MCP clients that support MCP Apps show it in the chat for
  `createPost`, `getDraft` and `checkDraft`; it needs a draft. `renderPostPreview` returns a PNG of one.
- **A file on its own** has no preview for agents. Read `getMedia` for its kind, size, width, height and duration.
  Don't use `getMediaContent` to check a video: it returns the whole file as base64. The person sees each file on
  Files and each post on the schedule.

## Media from a page or file URL

To post a photo from a web page, or a file that's already online, import it instead of downloading and uploading it.

- `importMedia` (`POST …/media/import`, `media` scope; CLI `flaghand media import --url …`) with `{"url": "https://example.com/blog/launch"}`
  only lists `candidates`: the page's Open Graph and Twitter images, then the photos in its article (JPEG, PNG, WebP or
  GIF, at least 200 px on each side), each with `index`, `url`, `preview_url`, `width`, `height` and `alt`. A URL that
  is itself a photo, MP4, MOV or PDF is its one candidate. Nothing is saved.
- Look at them, then send `"pick": [2, 1]` to save those as uploads, in that order, each with the page's alt text and
  `source_url`. If one can't be saved, none are. A WebP is saved as a same-size JPEG so LinkedIn can post it; `warnings` says so.
- Or put `media_from` on the body (or on a thread's post) and skip the separate call: the URL, or
  `{"url": "…", "pick": [2]}`. Without `pick`, a page gives its first candidate and an X post all its media. `createPost`, `createDraft` and
  `updateDraft` import it in the same call and attach it after the part's `media`; the saved body holds the media ids,
  never the URL. Not with `options`.

```json
{ "kind": "x_post", "connection_id": "con_X",
  "body": { "text": "We shipped it.", "media_from": { "url": "https://example.com/blog/launch", "pick": [2] } } }
```

- A post by one of your connected X accounts (`https://x.com/<handle>/status/<id>`) lists its own photos, videos (the
  best MP4) and GIFs with their alt text, read through X's API with that account's login: one post read, spending
  `x_media_import` credits while credits are on. Another account's post, a repost or a quoted post's media is refused.
  The copies are deleted when X says the post was deleted, protected, suspended or withheld.

X, LinkedIn, YouTube, TikTok, Instagram, Facebook and Threads pages and files are never fetched as pages. Use only images you have the rights to post: your own, your company's, or ones the owner lets you use. A page's images belong to whoever made them, and a news article's photos usually belong to the outlet or a photo agency even when the story is about you. To show a page without the rights to its image, use a link card, which links back to it. Media your post reused from someone else's post is still theirs.

## Add media to an existing draft in one call

Use `updateDraft` (`PATCH …/drafts/{id}`) with its current `rev` and `body_patch`. Omitted fields stay unchanged:

```json
{ "rev": 3, "body_patch": { "media_add": [{ "media_id": "med_…", "alt": "Weekly views" }] } }
```

Or import and append a photo in that call: `{"rev":3,"body_patch":{"media_from":"https://example.com/chart.png"}}`
(`media` scope required). No need to resend the text or existing media ids. CLI:
`flaghand drafts update drf_… --rev 3 --body-patch '{"media_add":[{"media_id":"med_…"}]}' --json`.
MCP uses the same `body_patch`; `getOperation` for `updateDraft` returns its complete schema.

`media` replaces the attachment list; `media_add` appends uploaded ids and `media_from` appends imported files.
`null` removes an optional field, so switching a LinkedIn card to a photo is
`{"rev":3,"body_patch":{"card":null,"media_add":[{"media_id":"med_…"}]}}`.
Other arrays and nested objects replace. On a thread, `body_patch.posts` is one positional patch per existing post:
`{"posts":[{"media_add":[{"media_id":"med_…"}]},{}]}` keeps both posts' text. Replace `body` to add, remove or reorder
posts. `body` remains a complete replacement for existing clients; do not combine it, `options` or a kind change with
`body_patch`.

To add media and schedule the plan together, send `draft_id`, `rev` and `body_patch` on that item in the one
`createPost` call, alongside the other items in the plan.

## Media in a body

A media reference is `{ "media_id": "med_…", "alt": "…" }` (`alt` optional).

- `x_post`: `"media": [ … ]`, up to 4.
- `x_thread`: up to 4 on each post, in that post's `media`.
- `linkedin_post`: up to 20 photos, **or** one MP4 video on its own, **or** a PDF document, **or** a link card, **or**
  a poll; not two of them. LinkedIn has no alt text for video, so a video's alt isn't sent.
- TikTok photo posts, videos and slideshows: the [TikTok guide](https://app.flaghand.com/docs/tiktok.md) and
  [slideshows](https://app.flaghand.com/docs/slideshows.md).

```json
{ "kind": "x_post", "connection_id": "con_X",
  "body": { "text": "Weekly charts are here.", "media": [{ "media_id": "med_…", "alt": "Weekly views, up 40%" }] } }
```

## Review a lighter cut first

For a 720p cut before a 1080p final, set `review_cut: true`, schedule it, then attach the final to the job. It publishes only if the final verifies as the same video: [Review cuts](https://app.flaghand.com/docs/approvals#review-cuts-approve-once-attach-the-final).

## X threads

A thread is **one** `x_thread` draft with its posts in order: one entry on the schedule. Never make drafts that
reply to each other.

```json
{ "kind": "x_thread", "connection_id": "con_X", "post_at": "2026-11-03T09:30:00-08:00",
  "body": { "posts": [
    { "text": "We shipped weekly charts today.", "media": [{ "media_id": "med_…", "alt": "Weekly views, up 40%" }] },
    { "text": "How it works: every week of your numbers side by side, in one view." },
    { "text": "Try it on your own data and tell us what you'd add next." } ] } }
```

- 2 to 25 posts, each up to 280 weighted characters (a link counts 23, an emoji 2) and up to 4 media. Each is posted
  as a reply to the one before. A thread is never split or merged for you.
- Only `posts[0]` may have a `poll` or `reply_settings`. `quote_url` and `reply_to_url` apply to post 1.
- When you replace `body`, send its whole `posts` array. To keep the structure and edit selected fields, use the positional `body_patch.posts` above.
- A single `x_post` may run to 25,000 weighted characters when the account's X subscription allows longer posts; the
  check tells you when it doesn't (`shorten-text`). Otherwise make it a thread.

## Replies and quotes on X

- `reply_to_url` is only for a post that's already live: the account's own post, or one that mentions or quotes it
  (X's API refuses other replies; the check offers replying by hand or posting it as a new post).
- `quote_url` needs the owner to post by hand: X's API no longer quotes posts. On an `x_post`, use
  `"by_hand": "all"`; on a thread, `"first"` or `"all"`. Or drop the quote.
- The draft (and a waiting hand-first job) carries `handoff_url`: an
  `https://x.com/intent/post?text=…&attachment_url=…` link with the **opening text and quote target**.
  Give it to the person as “Quote on X”; it opens a separate X composer, never publishes automatically. The person adds
  any planned media or poll in X. Agents never open or submit it. After posting, record the live link separately;
  opening the composer is not proof of a post. The field disappears when the hand step is done.
- `@handles` are posted as typed and aren't checked: Flaghand reads nothing from X outside its API, so `checkXMention`
  returns only the handle's x.com link (`checked: false`). Use a handle only when your source gives it exactly.

## Who posts it: `by_hand`

Who posts each part is part of the schedule.

**Patreon is always BY HAND.** Every `patreon_post` requires `by_hand: "all"`, an explicit campaign `connection_id`
and the owner's passkey confirmation before its handoff is scheduled. Use `createPost` or `requestApproval` with
`mode: "schedule"`, never direct `schedulePost`. The person publishes at the [Patreon handoff](https://app.flaghand.com/docs/patreon.md).
Its original images cannot be verified through Patreon's API; recording a link is not publication confirmation.

- Left out, on networks that support automatic posting: Flaghand posts all of it at its time. Not valid for Patreon.
- `"first"` (threads): the owner posts post 1 in X themselves; once it's live, Flaghand posts the rest under it.
  Request it with `mode: "schedule"`.
- `"all"`: the owner posts all of it themselves. On X or LinkedIn, record the live link after posting with
  `recordPostedByHand` (`POST …/drafts/{id}/posted-by-hand`, `{"url": "https://x.com/…"}`). Patreon instead needs a
  uniquely matching published post from its signed webhook or campaign-post reads; a supplied link is not proof.

Use `by_hand` only when the person wants it or the platform requires it, and say in the request's `note` exactly what
they do by hand. Never promise automatic posting for a hand step.

After a live LinkedIn post is edited on LinkedIn, record its complete current text with `recordLiveEdit`
(`POST …/jobs/{id}/record-live-edit`, `{"text":"…","note":"Edited on LinkedIn."}`). This updates the stored live
copy and keeps the history without calling LinkedIn; it is not another `posted-by-hand` action or proof from LinkedIn.
To add a missing link, use `requestLiveLink` with `link_url` and optional `label`: LinkedIn requests an in-place edit
of a post Flaghand published; X requests a self-reply. Both go to the owner; agents never send them.
[Live follow-ups and outside edits](https://app.flaghand.com/docs/schedule-and-results#add-a-link-to-a-live-post) has the HTTP, CLI and MCP flow.

## Polls

- X: `"poll": { "options": ["Better charts", "More exports"], "duration_minutes": 1440 }` on an `x_post` (or
  `posts[0]`). 2 to 4 options of 1 to 25 characters, 5 to 10,080 minutes; no media or quote on that post.
  `reply_settings` (`following`, `mentionedUsers`, `verified` or `subscribers`; omit for everyone) limits who can reply.
- LinkedIn: `"poll": { "question": "What should we build next?", "options": ["Better charts", "More exports"], "duration": "THREE_DAYS" }`.
  A question of 1 to 140 characters, 2 to 4 options of 1 to 30, and `ONE_DAY`, `THREE_DAYS`, `SEVEN_DAYS` or
  `FOURTEEN_DAYS`; no photos, video or link card on that post.

## LinkedIn link cards, documents and tags

- **Link card:** `createLinkCard` (`POST …/link-cards`, `media` scope) with `{"page_url": "https://example.com/article"}`
  reads the page's title, description and image and answers `card` (its image saved as media) and the page's photo
  `candidates`. Look at the card's image: when it's a plain background or a logo, call again with `image_url` set to a
  better candidate's `url`. Put that `card` in the `linkedin_post` body instead of media. X, LinkedIn, YouTube, TikTok
  and Meta pages can't be read: supply their card by hand. When a draft stops using an image Flaghand fetched for its
  card, the unused generated thumbnail is removed. Customer uploads and imports are never auto-deleted; another draft,
  offered option, Reset original or active job/download still using a thumbnail keeps it until those references go.
- **PDF document (carousel):** upload the PDF (1 to 300 pages), then `"document": { "media_id": "med_…", "title": "Plan your week" }`
  on its own, without photos, video or a card. The scheduled post keeps the PDF's bytes and its title.
- **Tags:** write `@[Exact Page Name]` in the text. Link each page once per workspace with `linkLinkedInTag`,
  supplying its URL and organization ID. New and edited drafts automatically fill missing `body.tags` entries from
  those links, including your own Page on every post that mentions it. You do not need to repeat its URN.
  `body.tags` remains optional; an explicit entry such as
  `[{ "name": "Acme", "kind": "organization", "urn": "urn:li:organization:1" }]` wins for that name.
  Only mentioned pages are filled: no text or unmentioned tag is added. The saved draft and its scheduled post keep their exact
  destinations even if a workspace link changes later. A missing link or ID names the mention to fix.
  Use exact page names; never invent people tags or scrape LinkedIn.

## Operations on this page

The operation id is also the MCP tool's name; MCP says how to call it (`listed`: a default tool).

| Operation | HTTP | CLI | MCP | Scopes | Does |
| --- | --- | --- | --- | --- | --- |
| [`uploadMedia`](https://app.flaghand.com/docs/api/uploadMedia.md) | `POST /workspaces/{workspace}/media` | `flaghand media upload` | listed | `media` | Upload a photo, video, PDF document or SRT captions file (the raw bytes as the body) |
| [`importMedia`](https://app.flaghand.com/docs/api/importMedia.md) | `POST /workspaces/{workspace}/media/import` | `flaghand media import` | `callWriteOperation` | `media` | List a web page's photos, a file at a URL or your X post's media, or save the ones you pick |
| [`listMedia`](https://app.flaghand.com/docs/api/listMedia.md) | `GET /workspaces/{workspace}/media` | `flaghand media list` | `callReadOperation` | `read` | The media library (uploads; a slideshow's rendered slides are in its render) |
| [`getMedia`](https://app.flaghand.com/docs/api/getMedia.md) | `GET /workspaces/{workspace}/media/{id}` | `flaghand media get` | `callReadOperation` | `read` | One media item |
| [`probeMedia`](https://app.flaghand.com/docs/api/probeMedia.md) | `GET /workspaces/{workspace}/media/{id}/probe` | `flaghand media probe` | `callReadOperation` | `read` | Read a stored file's dimensions and duration without changing its metadata |
| [`updateMedia`](https://app.flaghand.com/docs/api/updateMedia.md) | `PATCH /workspaces/{workspace}/media/{id}` | `flaghand media update` | `callWriteOperation` | `media` | Change a media item's default alt text (drafts keep their own copy) |
| [`createLinkCard`](https://app.flaghand.com/docs/api/createLinkCard.md) | `POST /workspaces/{workspace}/link-cards` | `flaghand link-cards create` | `callWriteOperation` | `media` | Fetch a page's link card and save its image to this workspace |
| [`checkXMention`](https://app.flaghand.com/docs/api/checkXMention.md) | `POST /workspaces/{workspace}/lookups/x-profile` | `flaghand mentions check-x` | `callWriteOperation` | `read` | An X @handle's x.com link, not checked (Flaghand doesn't read X profiles): open it and check the account yourself |
| [`linkLinkedInTag`](https://app.flaghand.com/docs/api/linkLinkedInTag.md) | `POST /workspaces/{workspace}/lookups/linkedin-tag` | `flaghand mentions link-linked-in-tag` | `callWriteOperation` | `drafts` | Link a LinkedIn @[Tag] by hand; people without a person URN post as plain text |
| [`recordPostedByHand`](https://app.flaghand.com/docs/api/recordPostedByHand.md) | `POST /workspaces/{workspace}/drafts/{id}/posted-by-hand` | `flaghand jobs record-posted-by-hand` | `callWriteOperation` | `drafts` | Record an approved draft its owner posted themselves; an optional known link is not platform verification |

Also complete on their own: [set up and connect](https://app.flaghand.com/docs/setup.md),
[drafting](https://app.flaghand.com/docs/drafting.md), [schedule and results](https://app.flaghand.com/docs/schedule-and-results.md),
[billing](https://app.flaghand.com/docs/billing.md) and [errors](https://app.flaghand.com/docs/errors.md). Every body field:
[drafts and media](https://app.flaghand.com/docs/drafts-and-media.md).
