# Publish content

> Create posts and other platform content with Koil Publish Requests.

Use Publish Requests to create platform content through a Profile. Koil validates the request, runs the platform operation, and gives you one status to track.

Publish requests only create content. Edits, deletes, and moderation of an existing item are synchronous calls on its own path, `/v1/profiles/{profileId}/content/{collection}/{externalId}`, that answer with the result. A create runs as a tracked request because it can wait for media or a schedule and its platform call cannot safely be repeated; a change to an item that already has an id finishes within the request. See [Creating and changing content](https://docs.koil.co/concepts/content#creating-and-changing-content).

Start here after you have a Profile from [Connect platform accounts](https://docs.koil.co/guides/connect-platform-accounts): its `id` is the `profileId` each item names.

## How it works

1.  Check what the Profile can publish. `GET /v1/profiles/{profileId}/capabilities`
    
2.  Choose a supported `collection` and, when required, a `variant`.
    
3.  Upload or stage media if the publish schema requires it. `POST /v1/media`
    
4.  Submit one or more publish items. `POST /v1/publish-requests`
    
5.  Store each returned `id`. `publishRequests` answers every item, in order, as the publish request its read returns; an item that could not be started carries an `error`, and the others proceed.
    
6.  Follow the request until it settles: `succeeded`, `failed`, `cancelled`, or `outcome_unknown`. Read its status, or [subscribe](https://docs.koil.co/guides/subscribe-to-events) to `publish_request.*`: each event carries the request exactly as this read returns it. A reply or message usually settles within seconds, so you can also [wait for it](https://docs.koil.co/guides/publishing#waiting-for-the-outcome) in the submission's response. `GET /v1/publish-requests/{publishRequestId}`
    

To change scheduled work, cancel it before it runs and submit a new request. `POST /v1/publish-requests/{publishRequestId}/cancel`

## Example

```bash
curl -X POST "https://api.koil.co/v1/publish-requests" \
  -H "Authorization: Bearer $KOIL_API_KEY" \
  -H "Koil-Version: 2026-12-08" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
  "publishRequests": [
    {
      "collection": "instagram.media.posts",
      "variant": "feed",
      "profileId": "prof_123",
      "scheduledAt": "2026-05-01T10:00:00Z",
      "args": {
        "text": "Hello world",
        "media": [
          {
            "mediaId": "med_123",
            "altText": "A cat"
          }
        ]
      },
      "metadata": {
        "campaign": "campaign-42",
        "draft": "draft-1"
      }
    }
  ]
}'
```

What goes in `args` depends on the collection and variant: each [platform page](https://docs.koil.co/platforms) lists the `args` of every publish, per variant.

Koil validates `collection`, `variant`, and `args` before anything is sent to the platform. If one item in a batch is invalid, the batch is rejected with every problem named, and nothing runs.

## Waiting for the outcome

The submission answers `202 Accepted`, with each item as it stood when Koil answered. To have the response carry the outcome, such as a reply's `externalId`, send the [RFC 7240](https://www.rfc-editor.org/rfc/rfc7240) header `Prefer: wait=<seconds>`. Koil starts the items as usual, then holds the response until every item has its outcome (`succeeded`, `failed`, `cancelled`, or `outcome_unknown`) or the wait runs out, for at most 10 seconds:

```http
Prefer: wait=10
```

-   `200 OK`: every item has its outcome, as its read returns it.
-   `202 Accepted`: the wait ran out first. Each item is as it stood then; follow it by events or reads as usual.

Only a submission that asks to wait answers `200`. Without `Prefer: wait` it answers `202` even when every item already has its outcome (an item that could not be started is `failed` at once), so take each item's outcome from its `status`, not from the response status.

`Preference-Applied: wait=<seconds>` names the longest Koil holds the response: your wait, or 10 seconds if you asked for more.

Koil never waits out a schedule: an item with `scheduledAt` stops holding the response once it is `scheduled`, and the submission answers `202`. An item waiting for its media holds it like any other item, so a post whose upload has not arrived answers `202` when the wait runs out. Koil ignores a preference it does not support and a `Prefer` it cannot read, and answers as if you had sent neither.

## Scheduling

Set `scheduledAt` on an item, beside `profileId`, to run it later; leave it out to publish now. It is an RFC 3339 date-time in the future, at most 365 days ahead.

Koil holds the item and sends it to the platform at that time, so every collection can be scheduled. The request reports `scheduled` until then, and its read and its `publish_request.scheduled` event carry the same `scheduledAt`.

The item is validated when you submit it, but the platform applies its own rules when the item runs. A message scheduled past the platform's messaging window, or a reply to a comment deleted in the meantime, fails then with the platform's error.

`scheduledAt` never goes in `args`. YouTube's `args.scheduledPublishAt` is a different setting: Koil uploads the video as private, now or at `scheduledAt`, and YouTube makes it public at `scheduledPublishAt`.

## Media Inputs

Use `mediaId` for images, videos, and other assets whenever possible. Koil can stage, validate, and reuse the media before the platform request runs.

Some publish schemas also accept `sourceUrl`. Use HTTPS URLs only. Koil creates the media from it when you submit the request, then fetches it.

You don't need to wait for media to finish processing before you publish. Reference a `mediaId` as soon as you have created it or uploaded its file, or pass a `sourceUrl`: Koil holds the publish until the media is ready, then checks it against the destination. A request you cancel while it waits is `cancelled`.

Because those checks need the processed media, a problem with it arrives after the request is accepted, as a `failed` request and its `publish_request.failed` event with `validation_error`. That covers media that failed processing (the message names the `mediaId` and why, as the media object's `error` does), an upload that never arrived, and media that doesn't meet the destination's requirements. A scheduled publish is checked once its media is ready, not at its scheduled time.

Every asset, uploaded or fetched from a `sourceUrl`, must fit these limits; each destination may add its own format, dimension, and duration requirements. An image or video that misses a destination's format, size, or frame-rate requirement is converted to fit, which in live mode needs a paid plan; the [sandbox accepts it without converting it](https://docs.koil.co/sandbox#limits). Audio files (MP3, AAC, M4A, Ogg, AMR) and documents (PDF, Word, Excel, PowerPoint) are never converted: one a destination does not take is refused.

| Limit | Value |
| --- | --- |
| Image file size | 50 MB |
| Image dimensions (width × height) | 100 megapixels |
| Video file size | 1 GB |
| Audio file size | 25 MB |
| Document file size (PDF, Word, Excel, PowerPoint) | 100 MB |
| `mediaId` accepted by publish requests | 24 hours after creation |

Once an asset is `ready`, its media object (`GET /v1/media/{mediaId}`, and the `media.processed` event) reports what Koil measured: `width` and `height` as displayed, `format`, and for a video `durationSeconds`, `videoCodec` and `frameRate`, so you can check it against a destination's requirements before you publish.

An asset over a size limit fails processing, and its media object reports `failed`. A publish request that references a `mediaId` created more than 24 hours earlier is rejected with `validation_error` (violation `media_expired` at that media item's path): create the media again and reference the new `mediaId`. A publish scheduled for later only needs its media to be fresh when you submit it.

### When media is checked

Each [platform page](https://docs.koil.co/platforms) lists what its destinations take: what is published as is, what Koil converts, and what is refused. Koil checks an asset against those requirements as soon as it has processed it:

-   **Already processed when you submit** (a `mediaId` you reuse, or one you submit after its `media.processed` event): the asset is checked with the request. A problem rejects the batch with `validation_error`, one violation per problem at the asset's path, such as `media_duration_too_long` at `/publishRequests/0/args/media/0`, and nothing runs.
-   **Still processing, or a `sourceUrl`**: the request is accepted, and the asset is checked once it is processed. A problem then fails that publish request (`publish_request.failed`) with `validation_error`, and `meta.reason` saying why, such as `media_incompatible`.

To hear about a bad asset immediately, upload it first and submit once `media.processed` arrives.

Converting media (its format, codec, size, or frame rate) needs a paid plan. On the free plan, an asset that needs converting is refused with `media_transform_not_entitled`; send media that already meets the destination's requirements instead. The sandbox accepts such media without converting it.

A limit the connected account sets is checked only when the publish runs, since Koil reads it from the platform then: a TikTok account may allow shorter videos than TikTok's own maximum, and a longer one fails the publish request with a message naming the account's limit.

## Batches and retries

`POST /v1/publish-requests` accepts up to 100 items or a 1 MB body, whichever is lower. Koil validates the request first, then runs accepted items independently.

Put your own ids in an item's `metadata`, such as `{ "campaign": "campaign-42", "draft": "draft-1" }`. Koil returns it on the publish request and on every `publish_request.*` event, so you can map each item back to the campaign and draft in your system.

Send an `Idempotency-Key` header when submitting publish requests. Koil requires it and dedupes the whole submit operation:

-   Reusing the same key and payload returns the first submission's result once it has answered: the items as they stood then. It does not wait again, so read the items for their current status. The response status follows the retry's own headers: `200` only if it sends `Prefer: wait` and every item in that result has its outcome, so a retry with the same headers gets the same status.
-   Reusing the same key with a different payload returns `409 conflict`.
-   To retry failed items, submit only those items with a new idempotency key.
-   A request that answered an error or died before answering (a timeout, a dropped connection) is safe to retry with the same key and payload: the retry resumes it, and items it already accepted keep their `id` and are not published again. While the first attempt may still be running (up to 15 minutes), including while it [waits](https://docs.koil.co/guides/publishing#waiting-for-the-outcome), the retry answers `409 conflict` with `Retry-After`. Only the same payload resumes it.

## When a publish fails

A failed publish carries an `error` in the same shape as an API error (`code`, `message`, `meta`), on the request and on its `publish_request.failed` event. A platform refusal carries the code it maps to with the platform's message, and `meta.refusalReason` where it is one you can act on, such as `messaging_window_closed` or `publishing_limit_reached` ([refusal reasons](https://docs.koil.co/concepts/errors#platform-failures)); an `internal` error keeps no message. Media that cannot be prepared for the destination fails with `validation_error`, `meta.reason` saying why (`media_incompatible`, for one), and `meta.violations` naming each [media rule](https://docs.koil.co/concepts/errors#validation-errors) it breaks, at the item's path as you submitted it: `/args/media/1` is the second asset. A `failed` request published nothing: fix the cause and submit it again with a new `Idempotency-Key`.

A platform throttle refuses the call, so nothing was published and Koil retries it: it waits as long as the platform's `Retry-After` asks (longer each time when the platform doesn't say) and calls again, a few times, before the request fails with `platform_rate_limit`. A throttle the platform says will last longer than a few minutes, such as a spent daily quota, fails the request right away rather than publishing it hours late.

`outcome_unknown` means the call that creates the content failed ambiguously: it timed out, the connection dropped, or the platform answered with a server error. The platform may have published it. Koil never retries that call, because platforms offer no way to make it safe to repeat. Check the platform (the profile's recent posts or comments) before submitting again, or the content may appear twice.

A reaction on LinkedIn, or in a Facebook or Instagram conversation, never ends `outcome_unknown`. The account has one reaction per item there, and repeating the call sets it again rather than adding a second, so Koil retries a failed call a few times and records `failed` if it keeps failing.

To test how you handle both in [sandbox mode](https://docs.koil.co/sandbox#apps-and-magic-grants), publish through a Profile on a Connection created from a `publish_rejected` or `publish_outcome_unknown` magic grant: a publish through it ends `failed` or `outcome_unknown`, with the error and `publish_request.*` events a live failure of that kind produces.

## What not to send

Use Koil fields in `args`. Do not send raw platform payloads or platform OAuth credentials.
