# Submit one or more publish requests

`POST https://api.koil.co/v1/publish-requests`

Submit one or more publish requests. Each item creates platform content — a post, a comment, a reply, a message — through a Profile. Every item's `args` is validated against its collection's publish input first and the submission is rejected whole if any item fails; each item then runs independently with its own `pub_*` ledger entry. Requires an `Idempotency-Key`. Answers `202` with each item as it stands. Sent with `Prefer: wait=<seconds>`, it waits up to that long (at most 10 seconds) for every item's outcome, and answers `200` if every item then has one.

## Authorization

An API key from the Koil admin console, sent as `Authorization: Bearer <key>`. A live key starts `koil_live_` and a sandbox key `koil_sandbox_`; the key alone selects the Organization and mode. See https://docs.koil.co/concepts/authentication.

## Parameters

| Name | In | Required | Type | Description |
| --- | --- | --- | --- | --- |
| `Koil-Version` | header | yes | `"2026-12-08"` | The dated API version the request is written against; it fixes the request and response shapes. Every response echoes the version it is rendered in. |
| `Idempotency-Key` | header | yes | string | A unique key for this request, scoped to the Organization and operation. Retrying with the same key and payload returns the first result instead of repeating the work, or runs a request that failed again; the same key with a different payload is refused with `409 conflict`. Keys expire 24 hours after first use, and a request still in flight after 15 minutes releases its key to a retry with the same payload. |
| `Prefer` | header | no | string | RFC 7240 preferences. `wait=<seconds>` holds the answer until every item has its outcome or is `scheduled`, for at most that long and never more than 10 seconds. Any other preference, or one Koil cannot read, is ignored. |

## Request body

`application/json`

- `publishRequests` (array of one of 23 shapes (InstagramMediaPostsPublishRequestInput, InstagramMediaCommentsPublishRequestInput, InstagramStoriesPostsPublishRequestInput, …), required) (min 1 items, max 100 items)

Every named shape is in the [OpenAPI document](https://docs.koil.co/openapi.json) under `components.schemas`.

## Example

Comment on a video through a sandbox channel:

```bash
curl -X POST "https://api.koil.co/v1/publish-requests" \
  -H "Authorization: Bearer $KOIL_API_KEY" \
  -H "Koil-Version: 2026-12-08" \
  -H "Idempotency-Key: <Idempotency-Key>" \
  -H "Content-Type: application/json" \
  -d '{"publishRequests":[{"collection":"youtube.videos.comments","profileId":"sandbox_prof_4T2cgH9gnSqEb9DrntKA","args":{"target":{"kind":"youtube.videos.posts","externalId":"sandbox_video_1"},"text":"Hello from Koil"}}]}'
```

## Response 200

The request asked to wait (`Prefer: wait`), and every item has its outcome: `succeeded`, `failed`, `cancelled` or `outcome_unknown`. `publishRequests` has one entry per submitted item.

- `publishRequests` (array of object, required) (min 1 items, max 100 items)
  - `kind` (`"publish_request"`, required): The kind of resource this is.
  - `mode` (one of `"live"`, `"sandbox"`, required): Which mode the resource belongs to. Live and sandbox resources are separate: a key reads and writes only its own mode's.
  - `id` (string, required) (min length 1)
  - `status` (one of `"created"`, `"scheduled"`, `"cancelled"`, `"started"`, `"succeeded"`, `"failed"`, `"outcome_unknown"`, required): `outcome_unknown`: The call that creates the content failed ambiguously (a timeout, a dropped connection, a platform 5xx), so the platform may have published it. Koil does not retry it. Check the platform before submitting again, or the content may be published twice.
  - `collection` (string, required) (min length 1)
  - `variant` (string) (min length 1)
  - `profileId` (string, required) (min length 1)
  - `scheduledAt` (string, date-time): When Koil runs the publish, as an RFC 3339 date-time. On a submission it must be in the future and at most 365 days ahead; omit it to publish now.
  - `externalId` (string) (min length 1)
  - `error` (object)
    - `code` (one of `"validation_error"`, `"not_supported"`, `"unauthorized"`, `"quota_exceeded"`, `"permission_denied"`, `"scope_insufficient"`, `"connection_invalid"`, `"not_found"`, `"conflict"`, `"rate_limit_exceeded"`, `"platform_rate_limit"`, `"internal"`, `"service_unavailable"`, required): Stable error code. `validation_error` (400), `not_supported` (400), `unauthorized` (401), `quota_exceeded` (402), `permission_denied` (403), `scope_insufficient` (403), `connection_invalid` (403), `not_found` (404), `conflict` (409), `rate_limit_exceeded` (429), `platform_rate_limit` (429), `internal` (500, 502, 504), `service_unavailable` (503).
    - `message` (string, required): Human-readable summary.
    - `meta` (object, required): Structured detail; the keys depend on `code`.
      - `violations` (array of object): Every problem with the request. Always present on a `validation_error`.
        - `code` (string, required): Stable violation code, such as `missing_field`, `unknown_field`, `schema_error`, `invalid_value` or `invalid_combination`.
        - `path` (string, required): JSON pointer into the request: path, query and body fields share one pointer space (`/cursor`, `/publishRequests/0/args/text`), a header is `/headers/<lowercase name>`, and `""` is the request as a whole.
        - `message` (string, required): Human-readable explanation.
      - `budgets` (array of string): On a `rate_limit_exceeded`: every budget that refused the request: `organization` (every authenticated request), `profile` (a request that acts on a Profile, one budget per Profile) or `client_address` (requests with no key or a rejected one). Koil may add budgets; treat an unknown one as covering the whole Organization.
      - `profileIds` (array of string): On a `rate_limit_exceeded` whose `budgets` include `profile`: the Profiles whose budget is spent. Requests that act on other Profiles are unaffected.
      - `required` (array of string): On a `permission_denied`: the API key permissions the operation requires that the key lacks.
      - `limit` (integer): On a `quota_exceeded`: the cap that was reached.
      - `resourceType` (string): On a `not_found` or a `conflict` over an existing resource: the kind of resource, such as `profile` or `connection`.
      - `resourceId` (string): With `resourceType`: the id of the resource not found or already there.
      - `reason` (string): On a failed publish or backfill request, or a failed Connect Session, that Koil failed itself, not the platform: why, such as `media_incompatible`, `media_transform_not_entitled` or `subject_mismatch` (a reconnect authorized a different platform account than the Connection's).
      - `refusalReason` (one of `"messaging_window_closed"`, `"recipient_rate_limited"`, `"recipient_unavailable"`, `"publishing_limit_reached"`): Why the platform refused, where the code alone does not say what to do. `messaging_window_closed`: The platform takes a message to this person only inside a window that has closed: WhatsApp's 24-hour customer service window, the Messenger and Instagram messaging window, or TikTok's allowance since the person last wrote. It reopens when the person writes again. `recipient_rate_limited`: Too many messages to this one person in a short time; messages to others are unaffected. Retry after `Retry-After`. `recipient_unavailable`: The person cannot receive messages from this Profile: they blocked it or deactivated their account, or, on WhatsApp, the number has no account or an outdated app. Retrying does not help. `publishing_limit_reached`: The account's own publishing cap on the platform is spent: Instagram's 24-hour content publishing limit, YouTube's daily upload limit, or TikTok's limit on posts. Publish again once it resets.
  - `metadata` (object, required): Your own key-value pairs, up to 50 keys of at most 40 characters with string values of at most 500. An update merges into what is stored, and a key set to `""` is removed.
  - `createdAt` (string, date-time, required)
  - `updatedAt` (string, date-time, required)
  - `startedAt` (string, date-time)
  - `succeededAt` (string, date-time)
  - `failedAt` (string, date-time)
  - `cancelledAt` (string, date-time)

## Response 202

Accepted: the request did not ask to wait (`Prefer: wait`), or an item is still running or scheduled. `publishRequests` has one entry per submitted item, as it stood when Koil answered.

- `publishRequests` (array of object, required) (min 1 items, max 100 items)
  - `kind` (`"publish_request"`, required): The kind of resource this is.
  - `mode` (one of `"live"`, `"sandbox"`, required): Which mode the resource belongs to. Live and sandbox resources are separate: a key reads and writes only its own mode's.
  - `id` (string, required) (min length 1)
  - `status` (one of `"created"`, `"scheduled"`, `"cancelled"`, `"started"`, `"succeeded"`, `"failed"`, `"outcome_unknown"`, required): `outcome_unknown`: The call that creates the content failed ambiguously (a timeout, a dropped connection, a platform 5xx), so the platform may have published it. Koil does not retry it. Check the platform before submitting again, or the content may be published twice.
  - `collection` (string, required) (min length 1)
  - `variant` (string) (min length 1)
  - `profileId` (string, required) (min length 1)
  - `scheduledAt` (string, date-time): When Koil runs the publish, as an RFC 3339 date-time. On a submission it must be in the future and at most 365 days ahead; omit it to publish now.
  - `externalId` (string) (min length 1)
  - `error` (object)
    - `code` (one of `"validation_error"`, `"not_supported"`, `"unauthorized"`, `"quota_exceeded"`, `"permission_denied"`, `"scope_insufficient"`, `"connection_invalid"`, `"not_found"`, `"conflict"`, `"rate_limit_exceeded"`, `"platform_rate_limit"`, `"internal"`, `"service_unavailable"`, required): Stable error code. `validation_error` (400), `not_supported` (400), `unauthorized` (401), `quota_exceeded` (402), `permission_denied` (403), `scope_insufficient` (403), `connection_invalid` (403), `not_found` (404), `conflict` (409), `rate_limit_exceeded` (429), `platform_rate_limit` (429), `internal` (500, 502, 504), `service_unavailable` (503).
    - `message` (string, required): Human-readable summary.
    - `meta` (object, required): Structured detail; the keys depend on `code`.
      - `violations` (array of object): Every problem with the request. Always present on a `validation_error`.
        - `code` (string, required): Stable violation code, such as `missing_field`, `unknown_field`, `schema_error`, `invalid_value` or `invalid_combination`.
        - `path` (string, required): JSON pointer into the request: path, query and body fields share one pointer space (`/cursor`, `/publishRequests/0/args/text`), a header is `/headers/<lowercase name>`, and `""` is the request as a whole.
        - `message` (string, required): Human-readable explanation.
      - `budgets` (array of string): On a `rate_limit_exceeded`: every budget that refused the request: `organization` (every authenticated request), `profile` (a request that acts on a Profile, one budget per Profile) or `client_address` (requests with no key or a rejected one). Koil may add budgets; treat an unknown one as covering the whole Organization.
      - `profileIds` (array of string): On a `rate_limit_exceeded` whose `budgets` include `profile`: the Profiles whose budget is spent. Requests that act on other Profiles are unaffected.
      - `required` (array of string): On a `permission_denied`: the API key permissions the operation requires that the key lacks.
      - `limit` (integer): On a `quota_exceeded`: the cap that was reached.
      - `resourceType` (string): On a `not_found` or a `conflict` over an existing resource: the kind of resource, such as `profile` or `connection`.
      - `resourceId` (string): With `resourceType`: the id of the resource not found or already there.
      - `reason` (string): On a failed publish or backfill request, or a failed Connect Session, that Koil failed itself, not the platform: why, such as `media_incompatible`, `media_transform_not_entitled` or `subject_mismatch` (a reconnect authorized a different platform account than the Connection's).
      - `refusalReason` (one of `"messaging_window_closed"`, `"recipient_rate_limited"`, `"recipient_unavailable"`, `"publishing_limit_reached"`): Why the platform refused, where the code alone does not say what to do. `messaging_window_closed`: The platform takes a message to this person only inside a window that has closed: WhatsApp's 24-hour customer service window, the Messenger and Instagram messaging window, or TikTok's allowance since the person last wrote. It reopens when the person writes again. `recipient_rate_limited`: Too many messages to this one person in a short time; messages to others are unaffected. Retry after `Retry-After`. `recipient_unavailable`: The person cannot receive messages from this Profile: they blocked it or deactivated their account, or, on WhatsApp, the number has no account or an outdated app. Retrying does not help. `publishing_limit_reached`: The account's own publishing cap on the platform is spent: Instagram's 24-hour content publishing limit, YouTube's daily upload limit, or TikTok's limit on posts. Publish again once it resets.
  - `metadata` (object, required): Your own key-value pairs, up to 50 keys of at most 40 characters with string values of at most 500. An update merges into what is stored, and a key set to `""` is removed.
  - `createdAt` (string, date-time, required)
  - `updatedAt` (string, date-time, required)
  - `startedAt` (string, date-time)
  - `succeededAt` (string, date-time)
  - `failedAt` (string, date-time)
  - `cancelledAt` (string, date-time)

## Errors

Every error has the same shape: `{ "error": { "code", "message", "meta", "requestId" } }`. [Errors →](https://docs.koil.co/concepts/errors)

| Status | Meaning |
| --- | --- |
| 400 | `validation_error`: The request does not match the operation's input schema, fails an admission check, or the platform refused its content. `meta.violations` names every problem. `not_supported`: The platform, collection or resource does not offer this operation, such as exporting a `key` Connection's credential, which Koil never returns. |
| 401 | `unauthorized`: No API key, or a key Koil does not accept (unknown, revoked, or with a prefix that does not match its mode). |
| 402 | `quota_exceeded`: A cap is reached: a free-plan cap, which upgrading lifts (`GET /v1/billing-account` reports them), or a sandbox limit. `meta.limit` is the cap. |
| 403 | `permission_denied`: The API key is valid but lacks a permission the operation requires; `meta.required` names it. Use a key created with that permission. `scope_insufficient`: The credential lacks a scope the operation needs; `meta` names the missing scopes. `connection_invalid`: The platform credential behind the Profile no longer works; the end user must re-authorize. |
| 404 | `not_found`: The resource does not exist in this Organization and mode. |
| 409 | `conflict`: The request collides with current state: an idempotency key reused with a different payload or still in flight, a run already in progress, a publish that has already started, or a resource that already exists (`meta.resourceType` and `meta.resourceId` name it). Retry only when the response carries `Retry-After` (the key's first request is still in flight, or a sandbox Profile's collection hasn't had its first poll), after that many seconds. |
| 429 | `rate_limit_exceeded`: Koil's own rate limit for the key, Organization, Profile, or client address is spent (`meta.budgets` names which); retry after `Retry-After` seconds. `platform_rate_limit`: The platform throttled the call or the platform quota is spent; retry after `Retry-After` seconds. |
| 500 | `internal`: Koil or the platform failed, and the status says which: 500 when Koil failed, including a platform refusing how Koil made the call; 502 when the platform failed or answered something Koil cannot use; 504 when Koil's call to the platform timed out. The message is generic; retry with backoff. |
| 502 | `internal`: Koil or the platform failed, and the status says which: 500 when Koil failed, including a platform refusing how Koil made the call; 502 when the platform failed or answered something Koil cannot use; 504 when Koil's call to the platform timed out. The message is generic; retry with backoff. |
| 503 | `service_unavailable`: A service Koil needs to accept the request (API key validation or rate limiting) is unavailable. Nothing was attempted; retry after `Retry-After` seconds. The hosting edge can deliver this as a `504` with neither this body nor `Retry-After`, so treat a `502`, `503` or `504` alike as retryable, with backoff. |
| 504 | `internal`: Koil or the platform failed, and the status says which: 500 when Koil failed, including a platform refusing how Koil made the call; 502 when the platform failed or answered something Koil cannot use; 504 when Koil's call to the platform timed out. The message is generic; retry with backoff. |
| default | Any other failure. `error.code` names it; the HTTP status follows from it. |
