# Upload local files (MCP)

Source: https://ampost.io/docs/mcp/media-upload · Full reference: https://ampost.io/llms-full.txt

Each MCP tool is the REST operation of the same name: the same arguments (path parameters and body fields in one object), the same result as `structuredContent`, the same error codes and rate limits. `tools/list` shows only the tools the key's or app's scopes allow; another answers `INSUFFICIENT_SCOPE`. A failed call returns `isError: true` with the REST error body as text.

## Media Upload

`media[]` takes public URLs. When the user has a file on their device, or you have the file itself, get it a URL with a media upload:

1. `POST /api/media/uploads` (MCP `media_upload_create`). The result has `uploadPageUrl`, an Ampost page where the user picks files in a browser, and `uploadUrl` + `method` + `headers` for one direct upload. Both stop accepting files after 60 minutes (`expiresAt`).
2. Either show `uploadPageUrl` to the user (the part after `#` is a secret for this upload only; do not log or repeat it), or, if you can make HTTP requests and have the file, send it yourself: `PUT` the raw bytes to `uploadUrl` with every header in `headers` plus `x-content-type: <MIME type>`.
3. Poll `GET /api/media/uploads/{uploadId}` (MCP `media_upload_status`) every 3-5 seconds until the status is `completed`, `failed` or `expired`. `completed` comes with `files`, each already a `media[]` item (`url`, `type`, `mimeType`, `sizeBytes`, `width`, `height`, `durationSeconds`): pass them to `posts_create` as they are. Ampost checks each file's bytes and reads width, height and duration from them; images are re-saved without metadata (EXIF, GPS), so their URL differs from the one uploaded to. `failed` means the direct upload's content was not the type it was sent as (reason in `error`); create a new upload.

Limits are in `limits`: up to 35 files on the page, JPEG, PNG, WebP, MP4, QuickTime and WebM, up to 200 MB per file. This is the way to send videos and any file over 4 MB. Files Ampost stores or converts are at most 200 MB each: uploads, the URL media of a scheduled post (copied to Ampost storage when the post is created) and media it converts for a platform. A larger file goes only as a public URL in a post that is not scheduled and that the platform takes without conversion, up to the platform's own limit (`media.maxVideoSizeBytes` in GET /api/platforms, e.g. TikTok 4 GB, LinkedIn 500 MB, X 512 MB). Files that no post uses are deleted 24 hours after the upload was created, by the hourly cleanup; files used in a post stay with the post. At most 20 upload links accept files at once (`RATE_LIMITED` with `Retry-After` past that), and each of them holds 200 MB of the plan's media storage while it accepts files (`QUOTA_EXCEEDED` with `details.quota` `storedMediaBytes` when that does not fit). Media in Ampost storage is deleted when its post is discarded, and 7 days after the post is published or has failed (a retry after that needs new media).

### Start a media upload

`POST /api/media/uploads` · MCP tool `media_upload_create` · scope `media:write` · rate limit `mediaUpload` · success `201`

Get a way to upload a local file for a post. Media in posts_create must be a public URL; use this when the user has the file on their device or you have the file itself. Returns `uploadPageUrl`, an Ampost page where the user uploads files in a browser (in MCP, a client that supports URL elicitation asks the user to open it itself and leaves `uploadPageUrl` out), and `uploadUrl` + `method` + `headers` to PUT one file directly. Both stop accepting files after 60 minutes. Then poll media_upload_status; when it is completed, its `files` are `media[]` items for posts_create. Files that no post uses are deleted 24 hours after the upload was created (by the hourly cleanup). At most 20 upload links accept files at once (`RATE_LIMITED` with `Retry-After` past that), and each of them holds 200 MB of the plan's media storage while it accepts files (`QUOTA_EXCEEDED` with `details.quota` `storedMediaBytes` when that does not fit).

| Field | In | Type | Required | Description |
|---|---|---|---|---|
| `fileName` | body | string | no | File name for the direct upload, e.g. `launch.mp4`; it becomes the end of the file URL. Default `file`. Files uploaded on the page keep their own names. |

Example request:

```json
{
  "fileName": "launch.mp4"
}
```

Example response:

```json
{
  "id": "3c7e9a1b-5d2f-4e8a-9b6c-1f3d5a7e9c20",
  "status": "pending",
  "uploadPageUrl": "https://ampost.io/upload/3c7e9a1b-5d2f-4e8a-9b6c-1f3d5a7e9c20#token=one-time-token",
  "uploadUrl": "https://vercel.com/api/blob/?pathname=uploads%2F3c7e9a1b-5d2f-4e8a-9b6c-1f3d5a7e9c20%2Flaunch.mp4",
  "method": "PUT",
  "headers": {
    "authorization": "Bearer vercel_blob_client_...",
    "x-api-version": "12",
    "x-vercel-blob-access": "public",
    "x-add-random-suffix": "0"
  },
  "limits": {
    "maxFiles": 35,
    "maxSizeBytes": 209715200,
    "mimeTypes": [
      "image/jpeg",
      "image/png",
      "image/webp",
      "video/mp4",
      "video/quicktime",
      "video/webm"
    ]
  },
  "createdAt": "2026-10-06T12:00:00.000Z",
  "expiresAt": "2026-10-06T13:00:00.000Z"
}
```

### Get a media upload

`GET /api/media/uploads/{uploadId}` · MCP tool `media_upload_status` · scope `media:write` · rate limit `apiRead` · success `200`

Read a media upload: `pending` until files arrive, `completed` with `files`, `failed` with `error` (the direct upload's content was not the type it was sent as), or `expired`. Poll every 3-5 seconds after media_upload_create. Each item in `files` is a `media[]` item (`url`, `type`, `mimeType`, `sizeBytes`, `width`, `height`, `durationSeconds`): pass them to posts_create unchanged.

| Field | In | Type | Required | Description |
|---|---|---|---|---|
| `uploadId` | path | string | yes | Media upload id (UUID): `id` from media_upload_create |

Example response:

```json
{
  "id": "3c7e9a1b-5d2f-4e8a-9b6c-1f3d5a7e9c20",
  "status": "completed",
  "files": [
    {
      "url": "https://abc123.public.blob.vercel-storage.com/uploads/3c7e9a1b-5d2f-4e8a-9b6c-1f3d5a7e9c20/launch.mp4",
      "type": "video",
      "mimeType": "video/mp4",
      "sizeBytes": 18350112,
      "width": 1080,
      "height": 1920,
      "durationSeconds": 28
    }
  ],
  "createdAt": "2026-10-06T12:00:00.000Z",
  "expiresAt": "2026-10-06T13:00:00.000Z",
  "completedAt": "2026-10-06T12:03:41.000Z",
  "error": null
}
```

### Multipart Post Create

To upload files instead of passing URLs, send `POST /api/posts` as `multipart/form-data`: a `data` part with the JSON body and one part per file. A media item references its file with `{ "file": "<part name>" }`; type, MIME type, size, width, height and duration come from the file's bytes, and a file whose content is not its declared type gets `VALIDATION_FAILED` on `media[i].file`. Images are re-saved without metadata (EXIF, GPS). Every file part must be referenced exactly once. Accepted: JPEG, PNG, WebP, MP4, QuickTime and WebM.

The whole multipart request must be at most 4 MB (all files and the `data` part together); a larger one gets 413 `PAYLOAD_TOO_LARGE`, or over 4.5 MB a plain-text 413 `FUNCTION_PAYLOAD_TOO_LARGE` from the hosting edge. That fits images, not most videos: for anything larger use a media upload (above), which takes files up to 200 MB, or pass a public URL in `media[]`.

`data` part:

```json
{
  "targets": [
    {
      "platforms": [
        "instagram"
      ]
    }
  ],
  "text": "Uploaded straight from my laptop",
  "media": [
    {
      "file": "photo",
      "altText": "The new dashboard on a laptop"
    }
  ]
}
```

```bash
curl -X POST https://api.ampost.io/api/posts \
  -H "Authorization: Bearer amp_live_YOUR_KEY" \
  -F 'data=<the JSON above>' \
  -F "photo=@launch.jpg"
```
