# Guide: handle Beplan API errors

Every Beplan API error has the same shape and a stable code. Branch on the code, show the message, log the request id, and retry only what can succeed on a retry.

## The envelope

```json
{
  "error": {
    "code": "MISSING_PERMISSION",
    "message": "You don't have permission to do this.",
    "details": { "permission": "post:schedule" },
    "requestId": "req_…"
  }
}
```

- `code`: stable, upper-case, one HTTP status each. **Branch on it**, never on `message`.
- `message`: an English sentence written for people. It may be reworded at any time.
- `details`: extra facts for some codes (`details.scope`, `details.reason`, `details.retryAfterSeconds`, `details.issues` for validation errors…), described on the codes that have them. May be absent.
- `requestId`: also in the `X-Request-Id` header of every answer, errors and successes alike. Log it; quote it when you contact Beplan about a call.

Every operation in the [reference](https://beplan.io/docs/api/) lists the codes it can answer, and the [error codes page](https://beplan.io/docs/api/errors/) lists them all with their status and default message.

## Validation errors

`400` [`VALIDATION_FAILED`](https://beplan.io/docs/api/errors/#VALIDATION_FAILED) carries `details.issues`, a list of `{ path, message }`, one per field that failed. Fields you send that the operation does not know are ignored, not refused ([versioning](https://beplan.io/docs/guides/versioning/)). A body that is not JSON is `415` [`UNSUPPORTED_MEDIA_TYPE`](https://beplan.io/docs/api/errors/#UNSUPPORTED_MEDIA_TYPE): send `Content-Type: application/json`.

## What to do, by class

| Status | Typical codes | Retry? | What to do |
|---|---|---|---|
| `400` | [`VALIDATION_FAILED`](https://beplan.io/docs/api/errors/#VALIDATION_FAILED) | No | Fix the request: `details.issues` names the fields |
| `401` | [`UNAUTHENTICATED`](https://beplan.io/docs/api/errors/#UNAUTHENTICATED), [`TOKEN_EXPIRED`](https://beplan.io/docs/api/errors/#TOKEN_EXPIRED), [`TOKEN_REVOKED`](https://beplan.io/docs/api/errors/#TOKEN_REVOKED), [`APP_SUSPENDED`](https://beplan.io/docs/api/errors/#APP_SUSPENDED) | No (an app refreshes once) | See [authentication](https://beplan.io/docs/guides/authentication/#expired-or-revoked) |
| `402` | [`PLAN_UPGRADE_REQUIRED`](https://beplan.io/docs/api/errors/#PLAN_UPGRADE_REQUIRED), [`SCHEDULED_POST_LIMIT_REACHED`](https://beplan.io/docs/api/errors/#SCHEDULED_POST_LIMIT_REACHED) | No | The organization's plan doesn't allow it, or a quota is used up. Tell the person |
| `403` | [`INSUFFICIENT_SCOPE`](https://beplan.io/docs/api/errors/#INSUFFICIENT_SCOPE), [`INTEGRATION_BLOCKED_BY_ORGANIZATION`](https://beplan.io/docs/api/errors/#INTEGRATION_BLOCKED_BY_ORGANIZATION), [`INTEGRATION_PENDING_APPROVAL`](https://beplan.io/docs/api/errors/#INTEGRATION_PENDING_APPROVAL), [`MISSING_PERMISSION`](https://beplan.io/docs/api/errors/#MISSING_PERMISSION) | No | Access: see [why a call was refused](https://beplan.io/docs/concepts/access/#why-a-call-was-refused) |
| `404` | [`ROUTE_NOT_FOUND`](https://beplan.io/docs/api/errors/#ROUTE_NOT_FOUND), [`ORGANIZATION_NOT_FOUND`](https://beplan.io/docs/api/errors/#ORGANIZATION_NOT_FOUND), [`WORKSPACE_NOT_FOUND`](https://beplan.io/docs/api/errors/#WORKSPACE_NOT_FOUND), `…_NOT_FOUND` | No | The thing doesn't exist, or isn't given to this connection. Refresh your ids |
| `409` | [`CONFLICT`](https://beplan.io/docs/api/errors/#CONFLICT), [`POST_CHANGED_ELSEWHERE`](https://beplan.io/docs/api/errors/#POST_CHANGED_ELSEWHERE), [`POST_OPEN_IN_EDITOR`](https://beplan.io/docs/api/errors/#POST_OPEN_IN_EDITOR), [`IDEMPOTENCY_KEY_REUSED`](https://beplan.io/docs/api/errors/#IDEMPOTENCY_KEY_REUSED) | Depends | Read the code: wait for `Retry-After` and retry ([`POST_OPEN_IN_EDITOR`](https://beplan.io/docs/api/errors/#POST_OPEN_IN_EDITOR), an idempotent request still running), or read again and reapply ([`POST_CHANGED_ELSEWHERE`](https://beplan.io/docs/api/errors/#POST_CHANGED_ELSEWHERE)), or use a new key ([`IDEMPOTENCY_KEY_REUSED`](https://beplan.io/docs/api/errors/#IDEMPOTENCY_KEY_REUSED)) |
| `413` | [`PAYLOAD_TOO_LARGE`](https://beplan.io/docs/api/errors/#PAYLOAD_TOO_LARGE), [`MEDIA_STORAGE_FULL`](https://beplan.io/docs/api/errors/#MEDIA_STORAGE_FULL) | No | Send less, or free storage |
| `415` | [`UNSUPPORTED_MEDIA_TYPE`](https://beplan.io/docs/api/errors/#UNSUPPORTED_MEDIA_TYPE) | No | Send JSON |
| `422` | Domain rules: [`POST_ALREADY_PUBLISHED`](https://beplan.io/docs/api/errors/#POST_ALREADY_PUBLISHED), [`SCHEDULED_AT_IN_PAST`](https://beplan.io/docs/api/errors/#SCHEDULED_AT_IN_PAST), `POST_LINK_*`… | No | The request is well formed but breaks a rule; the message says which |
| `429` | [`RATE_LIMITED`](https://beplan.io/docs/api/errors/#RATE_LIMITED) | Yes, after `Retry-After` | See [rate limits](https://beplan.io/docs/guides/rate-limits/) |
| `500` | [`INTERNAL_ERROR`](https://beplan.io/docs/api/errors/#INTERNAL_ERROR) | Yes, with backoff | Something failed on Beplan's side. Retry a few times, then report the `requestId` |
| `502` / `503` | [`UPSTREAM_FAILED`](https://beplan.io/docs/api/errors/#UPSTREAM_FAILED), [`SOCIAL_PLATFORM_UNAVAILABLE`](https://beplan.io/docs/api/errors/#SOCIAL_PLATFORM_UNAVAILABLE) | Yes, with backoff | A social platform or another service failed |

Some failures happen later, not in the answer: a scheduled post can fail when it is published. Follow it with [`GET …/posts/{postId}`](https://beplan.io/docs/api/posts/#posts.get) or the [`post.failed`](https://beplan.io/docs/webhooks/events/#event-post.failed) webhook.

## Retrying well

- Retry only `429`, `5xx` and the `409` codes that say to wait. Everything else fails the same way again.
- Wait the `Retry-After` header's seconds when there is one. Otherwise back off exponentially (1 s, 2 s, 4 s…) with some randomness, and give up after a few tries.
- Send an `Idempotency-Key` on every `POST` you might retry, and keep the same key across retries of the same request ([idempotency](https://beplan.io/docs/guides/idempotency/)). A `5xx` answer is never stored, so the retry runs again; a `2xx` or `4xx` one is replayed.
- `PATCH`, `PUT` and `DELETE` take no key. A `PATCH` with `baseUpdatedAt` is safe to retry: if the first attempt went through, the retry answers [`POST_CHANGED_ELSEWHERE`](https://beplan.io/docs/api/errors/#POST_CHANGED_ELSEWHERE) and you read the post to see.

## Through MCP

An MCP tool call that fails returns a tool error carrying the same `code` and `message`. A missing scope on an assistant's connection is an HTTP `403` with a `WWW-Authenticate` challenge naming the scope instead, so the assistant can ask the person for it ([MCP](https://beplan.io/docs/mcp/)).

---
HTML version: https://beplan.io/docs/guides/errors/
