> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Handle errors

> What each status means, the shape of an error answer, every error code, and when to send a request again.

Every answer is JSON, errors included. Read the HTTP status first. When the body has an `error` or a `code`, branch on that. `message` is written for people: you can show it to your user as it is.

## Status codes

| Status | What it means | Send it again? |
| - | - | - |
| `200`, `201` | Done. `201` means something was created. | |
| `400` | The request can't work as sent: a `PATCH /brand` body that isn't valid JSON, or LinkedIn mentions asked of an account that isn't on LinkedIn. | No. Fix the request. |
| `401` | No key, a wrong or deleted key, or one past its expiry date. See [Authentication](/docs/essentials/authentication.md#when-a-request-is-refused). | No. Check the key. |
| `402` | `insufficient_credits`: not enough AI credits for this request. | After adding credits. |
| `403` | The key lacks the [permission](/docs/essentials/authentication.md#permissions), the person's role doesn't allow it, their account is inactive, the plan doesn't include it (`plan_limit_reached`), or the key was sent to one of the PostSyncer app's own routes (`api_key_not_allowed`). | No. Change the key, the role, the plan or the route. |
| `404` | Not found, or in a workspace the key can't reach. | No. |
| `405` | The path exists, but not with this method. | No. |
| `409` | Something changed while you were working on it (`post_changed_elsewhere`), or the same work is already running. | After reading it again, or in a moment. |
| `415` | The body wasn't sent as JSON to `PATCH /brand`, `POST /brand/suggestion/accept` or `POST /brand/suggestion/dismiss`, which read JSON only. | No. Send `Content-Type: application/json`. |
| `422` | The request breaks a rule: a missing or wrong field, or something that can't be done to this item. | Usually no: fix what `message` and `errors` say. A few say to try again, such as a link that "could not be read right now" or a Google review reply: see the endpoint's page. |
| `429` | Too many requests this minute, or a limit on pay links, blog addresses read or invitations (`rate_limited`). See [Rate limits](/docs/rate-limits.md). | After `Retry-After` seconds. |
| `500` | Something broke on our side. | Once, after a moment. Check first for a `POST`: see [Send it again](#send-it-again). |
| `503` | Something we depend on can't answer right now: the AI, the media downloader, or storage. | Yes, after `Retry-After` when it's there, or after a minute. |

## Error shapes

### A message only

Most errors are a `message` and nothing else:

```json 403 theme={null}
{
  "message": "This API key does not have the \"posts:delete\" permission. Edit the key in PostSyncer under Settings → API to grant it."
}
```

Most `500`s say only `"Server Error"`, never the details of what broke. Uploads have their own words: see [Uploads](#uploads).

### Not found

Anything missing under `/api/v1` answers `404` with exactly this body:

```json 404 theme={null}
{
  "message": "Not found."
}
```

That covers an id that doesn't exist, an id in a workspace the key can't reach, a `GET /posts/by-url/…` or `GET /posts/by-platform-post-id/…` with no match, and a path that doesn't exist. The answer is the same for "doesn't exist" and "not yours", so it never shows what's in other workspaces.

* An id in the request **body** (`workspace_id`, `account_ids`, `media`, `parent_id`, the `post_id` of a comment) answers `422` on that field instead. See [Validation](#validation).
* [`POST /media/download/url`](/docs/api-reference/media/download-url) answers `404` with its own words and `"code": "post_unavailable"` when the social post is private, was removed, or doesn't exist. See [Answers with a code](#answers-with-a-code).

> [!NOTE]
>
> `DELETE /posts/{id}`, `DELETE /accounts/{id}`, `DELETE /labels/{id}` and `DELETE /campaigns/{id}` used to answer `422` with `Invalid … ID.` for an id the key can't reach. They answer `404` now, like every other path.

### Validation

A field that's missing or wrong answers `422` with `errors`: one entry for each field, each with a list of messages. A field inside a list has a dotted name, such as `accounts.0.id` or `urls.0`.

```json 422 theme={null}
{
  "message": "The post id field is required. (and 1 more error)",
  "errors": {
    "post_id": [
      "The post id field is required."
    ],
    "per_page": [
      "The per page field must not be greater than 100."
    ]
  }
}
```

That's `GET /comments?per_page=500`. `message` is the first error and, when there are more, says how many: `(and 1 more error)`, `(and 2 more errors)`. To show each problem next to its field, read `errors`.

Some `422`s are about the item, not a field, and have only a `message`. For example, deleting a folder that isn't empty:

```json 422 theme={null}
{
  "message": "Cannot delete folder that contains subfolders or media files. Please move or delete the contents first."
}
```

### Answers with an error code

These answers carry `error`, a code that stays the same while the words around it may change. Branch on `error`, not on `message`.

| `error` | Status | When | What to do |
| - | - | - | - |
| `plan_limit_reached` | `403` | The workspace owner's plan doesn't include this, or its limit is used up. Nothing was saved. See [below](#plan-limit-reached). | Tell the user. Only the workspace owner can change the plan. |
| `insufficient_credits` | `402` | An AI request (`POST /posts/analyze-twitter`, `POST /media/analyze-video`) costs more credits than are left. Nothing was charged. The body also has `credits_required` and `credits_available`. | Add credits, then send it again. |
| `post_changed_elsewhere` | `409` | You sent `content_version` on `PUT /posts/{id}`, and the post was changed since you read it. Nothing was saved. The body also has the post's current `content_version`. | Read the post again, apply your change to it, and send it with the new `content_version`. |
| `ai_unavailable` | `503` | The AI couldn't answer right now. | Try again in a minute. |
| `ai_declined` | `422` | The AI won't write this. | Change the wording. |
| `ai_answer_too_long` | `422` | The answer was too long to finish. | Send a shorter text. |
| `rate_limited` | `429` | A limit on pay links, blog addresses read or invitations is reached: see [Other limits](/docs/rate-limits.md#other-limits). Nothing was done. | Wait `Retry-After` seconds. `message` says how long, for the user. |
| `api_key_not_allowed` | `403` | The key was sent to one of the PostSyncer app's own routes. Keys work on `/api/v1`, the MCP server and [OAuth delegation](/docs/oauth-delegation.md). Nothing was done. | Use the matching `/api/v1` route or MCP tool where there is one. The rest, such as cancelling the plan, are done in the app. |

The `ai_unavailable`, `ai_declined` and `ai_answer_too_long` messages end by saying what happened to the credits: `You weren't charged.`, or how many came back.

```json 409 theme={null}
{
  "message": "This post was changed somewhere else since you opened it.",
  "error": "post_changed_elsewhere",
  "content_version": 4
}
```

Leave `content_version` out and an update always goes through, over any change made since. [Update a post](/docs/api-reference/posts/update.md) has the details.

### Plan limit reached

A `plan_limit_reached` answer has these fields:

| Field | What it holds |
| - | - |
| `limit` | What was reached: `accounts`, `posts`, `free_accounts` (a post to an account other than the 2 that Free posts to), `ai`, `moderation`, `contacts` (contact collection), `crm` (contacts and contact lists), `products`, `labels`, `campaigns`, `team` (inviting someone, or sending an invitation again) or `workspaces`. The app also refuses with `analytics`, which the API and MCP never send. |
| `used`, `allowed` | How many are used and how many the plan includes. Both are `0` for a feature the plan doesn't have. |
| `plan` | The workspace owner's plan, such as `free`. |
| `resets_at` | When the count starts again (ISO 8601), for `posts`. Otherwise `null`. |
| `owner_plan` | `true` when the plan isn't yours: the workspace belongs to someone else, and the message says to ask them. |
| `upgrade_url` | The billing page where the owner changes the plan. `null` when `owner_plan` is `true`. |
| `upgrade_plan` | The smallest plan that lifts the limit: `plan`, `name`, `monthly_price` and `yearly_price` (whole US dollars a month; `yearly_price` is billed yearly), `accounts`, `accounts_per_workspace`. `null` when `owner_plan` is `true`, or when no plan lifts it. |

Here, a key reaches a client's workspace whose owner is on Free and has connected 2 accounts:

```json 403 theme={null}
{
  "message": "This workspace's owner has connected 2 of 2 accounts on the free plan. Only the workspace owner can upgrade, so ask them to.",
  "owner_plan": true,
  "error": "plan_limit_reached",
  "limit": "accounts",
  "used": 2,
  "allowed": 2,
  "plan": "free",
  "resets_at": null,
  "upgrade_url": null,
  "upgrade_plan": null
}
```

[Plan limits](/docs/plan-limits.md) lists what each `limit` covers.

### Answers with a code

A few routes use `code` instead of `error`:

| Route | `code` values |
| - | - |
| [`POST /media/download/url`](/docs/api-reference/media/download-url) | `404` `post_unavailable`: the post is private, was removed, or doesn't exist. `422` when reading the link again won't help, such as `invalid_url`, `unsupported_url`, `login_required`, `geo_restricted`, `no_media`, `live_not_supported` or `file_too_large`. `503` `unavailable`, with `Retry-After`: try again later. |
| The file links that `POST /media/download/url` returns | `410` `link_expired`: read the post again for a new link. `403` `invalid_link`: use the link exactly as it was given. `502` or `503` `unavailable`: try again later. |
| `GET /accounts/{id}/linkedin/mentions` | `400` `INVALID_PROVIDER`: the account isn't on LinkedIn. |

[Get download links](/docs/api-reference/media/download-url.md) has every value.

## Uploads

`POST /media/upload/file` and `POST /media/upload/url` answer:

| Status | Body | Stored? |
| - | - | - |
| `422` | `errors.file`: the file is the wrong type, too large, or isn't an image, video, audio, PDF, Word or PowerPoint file. | Nothing. |
| `422` | `errors["urls.0"]`: `The media URL https://cdn.postsyncer.com/examples/latte-art.jpg could not be used:` and why (it couldn't be downloaded, or isn't allowed). | Nothing. |
| `422` | `{"message": "Upload failed: no media was stored."}` | Nothing. |
| `500` | `{"message": "Upload failed. Try again in a moment."}`: something broke on our side. | Usually safe to send again. |
| `503` | `{"message": "The media could not be saved. Please try again."}`: storage couldn't save a URL import. | Send it again. |

## The MCP server

MCP tools give the same `message` as the API, as a tool error (`isError: true`) instead of an HTTP status. There are a few differences:

* Validation errors come as one text with every message.
* Something missing says `Post not found or you do not have access.` (with the thing's name), or `Resource not found or you do not have access.`
* A plan limit states the limit and links the pricing page. It has no price and no `upgrade_url`. A key with `billing:create`, used by the workspace owner, gets a line offering a pay link with `create-billing-link` in place of the pricing link.
* The rate limit of 60 a minute is still an HTTP `429`, not a tool error. See [Rate limits](/docs/rate-limits.md). The limits on pay links, blog addresses read and invitations are tool errors with their `message`.

## OAuth delegation

[OAuth delegation](/docs/oauth-delegation.md) has its own errors. Starting a session (`POST https://postsyncer.com/api/oauth/delegate/sessions`) answers with `success`, `code` and `message`:

```json 403 theme={null}
{
  "success": false,
  "code": "missing_permission",
  "message": "This API key does not have the \"accounts:create\" permission. Edit the key in PostSyncer under Settings → API to grant it."
}
```

| `code` | Status | Why |
| - | - | - |
| `missing_api_key` | `401` | No key in the `Authorization` header. |
| `invalid_api_key` | `401` | The key is wrong, deleted or past its expiry date. |
| `account_inactive` | `403` | The key's owner can't use PostSyncer right now. |
| `missing_permission` | `403` | The key lacks `accounts:create`. |
| `unsupported_platform` | `422` | That network can't be connected this way. |
| `no_signing_secret` | `422` | The key has no signing secret yet. Make one in Settings → API. |

A missing or wrong `platform`, `callback_url` or `state` answers the usual [validation](#validation) `422` instead: `message` and `errors`, with no `success` or `code`.

After the person signs in, an error comes back to your `callback_url` as the query parameters `error`, `error_description` and `state`. `error` is one of `expired_request`, `invalid_state`, `provider_mismatch`, `unsupported_platform`, `redirect_failed`, `missing_platform_id`, `connection_failed`, or the network's own code, such as `access_denied`. Treat any callback with `error` as not connected, and start a new session.

## Agent sign-up

[`POST /agent-signup/code`](/docs/api-reference/agent-signup/code) and [`POST /agent-signup/verify`](/docs/api-reference/agent-signup/verify) answer with `error` and a plain `message` to pass on to the person. A wrong code also has `tries_left`.

```json 422 theme={null}
{
  "error": "code_wrong",
  "message": "That code isn't right. You can try 4 more times.",
  "tries_left": 4
}
```

| `error` | Status | When |
| - | - | - |
| `code_wrong` | `422` | The code isn't right. Ask the person to read it again while `tries_left` is above 0. |
| `code_expired` | `422` | The code is over 10 minutes old, was used, or was replaced by a newer one. Ask for a new code. |
| `too_many_tries` | `422` | The code was entered wrong 5 times. Ask for a new code. |
| `teammate_only` | `403` | The address is only a teammate in someone else's workspace. Only owners get keys. |
| `account_inactive` | `403` | The account is inactive. The person writes to [support@postsyncer.com](mailto:support@postsyncer.com). |
| `rate_limited` | `429` | A sign-up limit is reached. Try again after `Retry-After` seconds when it's given. |

A missing or wrong field answers the usual [validation](#validation) `422`. [Sign up from an AI agent](/docs/guides/agent-signup.md) has the limits.

## Send it again

* **`429`**: the request wasn't run. Wait `Retry-After` seconds, then send it again as it is.
* **`503`**: nothing was done. Wait `Retry-After` seconds when the answer has it, or a minute when it doesn't, then send it again as it is.
* **`409` `post_changed_elsewhere`**: read the post again first.
* **`500`, or no answer at all**: a read is safe to send again. A write may or may not have happened. For `POST /posts`, send an `Idempotency-Key` header: the same request with the same key returns the post it already made (`200` with `Idempotency-Replayed: true`) instead of making a second one. Without a key, list the posts (`GET /posts`) and check whether it's there before you send it again.
* **Any other `4xx`**: the same request gets the same answer. Change it first.

```javascript JavaScript theme={null}
// post: the body of the post you're creating.
const response = await fetch('https://postsyncer.com/api/v1/posts', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(post),
});

if (!response.ok) {
  const body = await response.json();

  if (response.status === 422 && body.errors) {
    // One list of messages for each field.
    console.log(body.errors);
  } else if (body.error === 'plan_limit_reached') {
    // Tell the user. body.limit says what was reached.
    console.log(body.message);
  } else {
    console.log(response.status, body.message);
  }
}
```

```python Python theme={null}
import requests

# post: the body of the post you're creating.
response = requests.post(
    "https://postsyncer.com/api/v1/posts",
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    json=post,
)

if not response.ok:
    body = response.json()

    if response.status_code == 422 and "errors" in body:
        # One list of messages for each field.
        print(body["errors"])
    elif body.get("error") == "plan_limit_reached":
        # Tell the user. body["limit"] says what was reached.
        print(body["message"])
    else:
        print(response.status_code, body["message"])
```

## Related

> [card] [Rate limits](/docs/rate-limits.md)
>
> 60 requests a minute, and how to wait out a `429`.

> [card] [Plan limits](/docs/plan-limits.md)
>
> What Free includes, and what's on paid plans.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.