# Errors

API refusals are JSON with a stable code and one plain sentence. `docs_url` links here; CLI JSON and MCP tool errors keep that field, JSON-RPC errors use `error.data.docs_url`, and OAuth/auth.md errors use `error_uri`. Relative links resolve against the API origin. Existing `next_step`, `Retry-After`, field fixes and owner-approval instructions take priority over generic retry advice:

```json
{ "error": { "code": "rev_conflict", "message": "The draft is at rev 4, not 3. Read it again and reapply your change." } }
```

Some carry more: `problems` or `drafts` (a check that failed: each problem with its fixes), `field` (the query
parameter or header at fault), or `next_step` (what the owner should do, including an add-card link for
`workspace_inactive`). Codes never change meaning. Messages may get clearer.

Payment links (`checkout_url`, including subscription recovery, and `portal_url`) are short `https://app.flaghand.com/pay#…`
Flaghand bearer links. Relay them and their `for_person` **verbatim**, including the entire `#` fragment; never substitute Stripe's destination.
Stripe's “This link is incomplete” means its required URL fragment was lost: use the original Flaghand link, which
restores the whole URL. Completed or expired Checkouts return to the original approval or Billing page, where the
person can review current terms and start again. A missing or cut-off Flaghand fragment shows an incomplete-link page
with a Billing link; request a fresh link through the existing billing operation or sign in and open Billing.
Legacy `/pay/…` links no longer resolve. No malformed or unknown link creates a session.

If recurring `startCheckout` has prepared a Checkout but cannot read or save its short payment link, it returns
`409 conflict` with `error.checkout_session_id` and `error.next_step`, not a replacement subscription. Continue card
entry in the already-open Checkout, or retry the same `startCheckout` arguments (including `plan` and `return_to`)
to recover it. The same answer applies during the original Checkout's card authentication. Never start a second
subscription to work around this error. A definitive workspace deletion/billing denial instead requires returning
to Billing and does not tell the person to continue card entry.

An incomplete, unpaid or paused subscription is not a new Checkout error or a request to sign up again:
`startCheckout` returns `200` with `checkout_url` for that subscription's original card authentication, invoice or Stripe
Portal, plus a plain `next_step` and matching `for_person`. Give the person that recovery link and its instructions unchanged; do not create
another subscription or quote another trial. A paused plan's resumption invoice must be paid before access resumes.
A current active, trialing or past-due plan still returns `conflict`; read Billing and use `openBillingPortal` for payment
updates. A Stripe failure remains retryable with the same recovery request, never a reason to open a competing plan.

For `getSetup`'s `connection_missing` issue, call `startConnection` for the intended platform, give the person its
`url` and unchanged `for_person` for consent, then wait on `getConnectionAttempt`. Starting the link is the agent's
step; only the person authorizes platform access. Pending returns `202` with `Retry-After: 5`, advice to read the
same attempt again in five seconds, not an enforced limit. Reading it never contacts a platform. Settings is the
fallback only when the token lacks `connections` scope, as every MCP connector's OAuth token does: then `getSetup`'s
`next` has no operation, and the owner connects the account in Settings before you read setup again.

| Code | HTTP | Means | What to do |
|---|---|---|---|
| `method_unavailable` | 503 | This person sign-in method is not configured here. | Choose a method the page offers; an agent must not collect the person's credentials. |
| `invalid_email_code` | 403 | The email link/code does not match this request or browser. | The person uses the link's Continue page, or enters the code in the requesting browser. |
| `email_link_browser_mismatch` | 403 | The email link belongs to a different browser request. | Open the link in the browser that requested the email, or type the same email's six-digit code there. |
| `email_code_expired` | 409 | The email proof's ten-minute deadline passed. | Request a fresh email; neither credential remains usable. |
| `email_code_used` | 409 | That email link or code was already consumed. | Continue in the signed-in browser, or request a fresh email. |
| `email_code_locked` | 409 | Five wrong codes disabled this request's code, not its link. | Use the link in the email, or request a fresh email when the sixty-second window permits. |
| `email_code_link_required` | 409 | Twenty consecutive wrong codes disabled codes for this address across requests. | The person uses the email link or freshly signs in another way to restore codes; resending alone does not restore them. |
| `email_not_verified` | 403 | The provider did not verify this email. | Choose another configured method; unverified email cannot match or link an account. |
| `identity_in_use` | 409 | This verified method belongs to a different account. | Sign in to the intended account; linking never moves another person's identity. |
| `email_code_required` | 409 | The provider isn't authoritative for this address, which belongs to an existing account. | The person signs in with a code emailed to that address, then adds the provider in Settings › Account. |
| `account_not_found` | 404 | Valid inbox/provider proof found no existing account. | Start signup to create an account; inbox proof alone does not accept terms or create one. |
| `invalid_request` | 400 | The request is missing something or has a field in the wrong shape. | Fix the field the message names. `field` names it when it is a query parameter or a header. |
| `invalid_json` | 400 | The request body isn't valid JSON. | Send valid JSON. |
| `unauthorized` | 401 | Sign in using a configured person method, or send an API token as a Bearer token. | **Chat apps: add `https://app.flaghand.com/mcp` as an OAuth connector first.** Its sign-in page creates the account free with any configured method, no card; return and click Allow. No separate site sign-up, shell or network/environment settings. **Shell/HTTP clients:** send `Authorization: Bearer tok_…`, or sign in. With no account, use `POST https://app.flaghand.com/api/v1/signup` with `{"email":"person@example.com"}`; see [Pick your path](https://app.flaghand.com/docs/setup.md#pick-your-path). |
| `invalid_token` | 401 | The credential is malformed, a redacted mask, unknown, revoked or expired; the message says which. | For a mask, malformed value or wrong prefix, read the complete saved token from private storage inside the request; never retype `***`, `<redacted>` or a quoted value. For "No API token matches", check the app origin and that the whole saved token arrived unchanged before requesting another. For "revoked" or "expired", reconnect the OAuth app or have the owner make a new token in Settings › Agents (`https://app.flaghand.com/agents`). Do not restart sign-up to fix a changed request. API, OAuth MCP and CLI credentials use these same checks; [credential recovery](https://app.flaghand.com/docs/sign-in-and-tokens.md#when-a-credential-is-refused). |
| `session_expired` | 401 | Your session ran out. Sign in again. | Sign in again. |
| `scope_missing` | 403 | This API token doesn't have the scope this route needs; the message names the required/missing scopes. | Have the workspace owner create a token with those scopes in Settings › Agents. Reconnecting OAuth cannot add unsupported scopes. This is not an unknown or revoked credential. |
| `permission_not_granted` | 403 | The account's owner left a permission unticked on the platform's consent page, so this read can't be done. Posting is unaffected. | Call `startConnection` with the `connection_id` in `fixes`, give the person its `url` and unchanged `for_person`, and ask them to leave every permission ticked. |
| `owner_session_required` | 403 | Only a signed-in workspace owner can do this. API tokens can't. | Ask the owner. Agents schedule future posts instead (`schedulePost` or `createPost`); posting now stays the owner's. |
| `bad_origin` | 403 | Requests signed in with a session cookie must come from the app's own origin. | Call from the app, or use an API token. |
| `approval_required` | 403 | The job lacks valid posting evidence for its exact snapshot. Immediate posting needs owner passkey approval; future agent schedules retain separate immutable evidence. | Read the draft and job. Use agent scheduling for a future post, or request owner approval for immediate posting. |
| `post_now_forbidden` | 403 | Agents cannot post immediately or choose a past or imminent time. | Use `schedulePost` or `updateScheduledPost` with a time at least one minute ahead. In a `createPost` or `requestApproval` check, choose a later `post_at`; posting now is the owner's (`mode: "post_now"` goes to their approval). |
| `passkey_failed` | 403 | The passkey check didn't pass. Try again. | Try the passkey again, or add a new one. |
| `step_up_required` | 403 | Confirm it's you first: with your passkey, or a code emailed to you if your account has none. Being signed in isn't enough to give an agent access. | The owner's, in the browser, for `createToken`, OAuth Allow and `allowSignup`: `startToken` says which; send its `challenge_id` and the passkey's `response`, or the `proof_token` from the emailed code, with the same request. Each works once, within 5 minutes. Agents never do this for the person. |
| `user_code_mismatch` | 403 | The code typed at a sign-up link's Allow step doesn't match that link's `user_code`. Nothing was allowed. | The person types the code their own agent showed with this link (the end of its `for_person`). If no agent of theirs started it, they don't allow it. A replaced link has a new code. An agent shows only the code of the link it started. |
| `not_found` | 404 | There's nothing here, or it belongs to a workspace you can't see. A token targeting another workspace gets the same refusal whether that workspace exists or not. | For a workspace refusal, call `GET https://app.flaghand.com/api/v1/me` / `flaghand me --json`, then correct the requested workspace or use its credential. Check `--workspace` and `FLAGHAND_WORKSPACE` too. No response confirms another account's workspace or keys. For an unknown sign-up claim code, start again with `POST https://app.flaghand.com/api/v1/signup` and `{"email":"person@example.com"}`. |
| `wrong_host` | 421 | The request went to Flaghand's old workers.dev address, which no longer serves the API, MCP, sign-in or any write. Nothing ran there; `origin` names the app's own origin. MCP answers JSON-RPC `-32003` with the same `data.code` and `data.origin`; OAuth and auth.md endpoints answer `error: "wrong_host"` with `error_description`. | Send the same request to `https://app.flaghand.com`; the same token works there. For the CLI, set `FLAGHAND_URL` (or `--url`) to `https://app.flaghand.com` or leave it unset; for MCP, connect to `https://app.flaghand.com/mcp`. |
| `method_not_allowed` | 405 | This route doesn't accept that method. | Use a method the message lists. A draft has no `DELETE`: the message names the archive call (`GET` for its `rev`, then `PATCH` with `archived: true`). |
| `not_denied` | 409 | Only the owner denies a draft. | Read the draft: a reason can be recorded only on its current, not-undone denial. Agents never deny. |
| `owner_reason` | 409 | The owner wrote why already. | Keep the owner's reason; a token cannot replace or clear it. |
| `draft_denied` | 409 | The owner denied this draft, so it can't change or be requested again. Read its denial and make a new draft. | Read the draft's `denial`, then create a new draft for anything you want to offer again. Only the owner can undo a denial. |
| `rev_conflict` | 409 | The draft changed since you read it. Read it again and reapply your change. | Read the draft again, reapply your change on top, send its new rev. |
| `draft_locked` | 409 | The draft is scheduled, being posted or posted, so it can't change. Cancel its job first. | Cancel the job first, then change the draft. |
| `draft_changed` | 409 | A draft changed after the approval was prepared, so nothing was approved. Prepare the approval again. | Prepare the approval again (`POST …/approvals/options`). |
| `job_exists` | 409 | This draft already has a job waiting, scheduled or posting. | Cancel that job first. |
| `queue_needs_time` | 409 / job result | A queue pause stopped this post or its approved time passed while paused. Saved live thread parts are retained. | Choose a new time, check and schedule it again. Only an owner resumes the workspace queue with a fresh passkey; resume never catches up missed posts. |
| `job_state` | 409 | The job isn't in a state that allows this. | Read the job; it may already be done. |
| `challenge_expired` | 409 | This authentication challenge expired or was already used. Ask for a new one. | Ask for a new challenge or link. For an expired sign-up claim code, start again with `POST https://app.flaghand.com/api/v1/signup` and `{"email":"person@example.com"}`, using the same email if the account already exists: the owner signs in on the new link, types its new `user_code` and allows the agent. |
| `conflict` | 409 | That conflicts with something that already exists. | Read the current state and try again. With an `Idempotency-Key`, a request with that key is still running or stopped before it answered: look where the message says (the drafts, the media library, …), then use a new key. |
| `billing_location_required` | 409 | The direct prepaid purchase has no payer country, or a US payer has no state; nothing is charged. | Obtain the actual fields named in `missing_fields` (`billing.country` or `billing.state`); supply `payPlan.billing` or persist the `billing` object through `updateBillingLocation` (`PATCH /workspaces/{workspace}/billing/location`), then request a quote. `getBilling.billing_location` reads the saved location. |
| `billing_location_changed` | 409 | The remembered billing location changed after this quote; nothing was charged. | Read `billing_location`, then execute the returned `next_action` to request a new quote with a new Idempotency-Key. Do not answer the stale challenge. An unclear payment outcome must still be recovered with its original payment_id. |
| `managed_payments_required` | 409 | The shared payer-country policy requires Managed Payments Checkout, not a direct prepaid charge; nothing is charged on the refused route. | Execute `next_action.operation` (`startCheckout`) with its returned `arguments`: `workspace`, `plan`, `mode:"payment"`, `managed_payments:true`; relay the person's Checkout link, never substitute recurring billing or another rail. [Country policy, cutoff and API/MCP/CLI handoff](https://app.flaghand.com/docs/billing.md#shared-payer-country-policy). |
| `recurring_subscription_active` | 409 | A renewing or unresolved recurring subscription already exists; prepaid cannot overlap or bypass it. | Use `manage_billing` or the existing invoice recovery. Only the person decides to stop renewal. If it is already set to end, prepaid begins after its paid-through date. |
| `payment_required` | 402 | A one-time purchase awaits a person-delegated payment credential, not workspace access or post approval. | Verify amount/currency/period and answer one of `challenges` for this `payment_id`; retry that same purchase after a lost reply, never buy a second period as recovery. See [prepaid payments](https://app.flaghand.com/docs/billing.md#prepaid-payments-for-agents). |
| `workspace_inactive` | 402 | This action needs a different billing state. `starting` allows drafting but not approval, scheduling, posting or best-times refresh; if the free start expires without a card, the workspace is `lapsed` and drafting also stops. A refused-and-canceled card trial does not shorten the original free drafting week or enable posting. | Follow `next_step` with the message's explanation. After a card-trial refusal, choose **Start your plan** on the approval link, or call `startCheckout` and relay its `checkout_url` and unchanged `for_person`; the next Checkout has no trial. Otherwise give the owner the add-card or billing link. For a ready plan, send its `approval_url`: the card step returns for normal passkey approval, and payment never approves. Reading, export and starting billing still work. |
| `media_storage_full` | 402 | New media would pass the no-card free start's 250 MB workspace storage limit, not a per-file size limit. `used_bytes` and `limit_bytes` give the exact counts. | Relay the one-line message and `next_step`. An accepted card trial or paid plan lifts the limit. After a refused card trial, follow **Start your plan**, not another trial. Necessary copies of media already stored still work. Read `getBilling.media_storage` for usage. |
| `signup_closed` | 403 | Sign-up isn't open yet. | Join the waitlist with `POST https://app.flaghand.com/api/v1/waitlist` and `{"email":"person@example.com"}` (no token needed), or the same JSON to `POST https://flaghand.com/api/waitlist`. Only submit an address whose person asked to join. |
| `payload_too_large` | 413 | The upload is too large. | Upload a smaller file. |
| `unsupported_media_type` | 415 | That content type isn't accepted here. | Send JSON, or a supported media type for uploads. |
| `check_failed` | 422 | The draft wouldn't post exactly as previewed. See problems for what to fix. | Apply the fixes in `problems` (or `drafts[].problems`) and check again. |
| `time_passed` | Problem in `problems` | The requested time has passed or is less than 2 minutes away. | Pick a later time, then check again. |
| `idempotency_key_reused` | 422 | That Idempotency-Key was already used with a different request. Send a new key with a new request. | Send a new `Idempotency-Key` (a fresh UUID) with each new request; resend a key only with the exact request it was first sent with. |
| `not_supported` | 422 | That isn't supported yet. | Leave that feature out for now. |
| `out_of_credits` | 402 | The workspace has no credits left for this read. Nothing was read and nothing was charged; the automation pauses. `message` is the pause line, with the date it resumes when the plan's credits arrive. Checking a live post again (`verifyJob`) answers it too, with nothing paused. On an approval it's a problem on the draft instead (`check_failed`): the post needs more credits than are free, and nothing was approved. | Relay `message` to the owner unchanged. Don't retry: the automation resumes by itself when credits arrive. The owner can add credits in Billing, or you can ask them once with `requestCreditPurchase` (they confirm and pay). See [Credits](https://app.flaghand.com/docs/credits.md). |
| `credit_budget_reached` | 409 | The automation reached the monthly credit budget its owner set. Nothing was read; it pauses until next plan month. | Relay `message`. Raise or clear the budget only if the owner asks (`updateAutomation`). |
| `credit_run_limit` | 409 | The run reached the most it was allowed: its `max_credits`, or voice learning's confirmed ceiling. What it read so far is kept. | Run again with a higher `max_credits` if the owner wants more. |
| `automation_off` | 409 | The automation is turned off in Automations. | Turn it on (`updateAutomation` with `enabled: true`) only if the owner asks. |
| `x_credits_exhausted` | 503 | Flaghand's prepaid X API balance ran out, not the workspace's plan or credits. Publishing jobs are held with this `error_code`, not failed. | Wait for a top-up; the owner retries the held job in the desk. Agents can read its reason but cannot resume it. Already-posted jobs stay posted if only read-back fails. |
| `final_pending`, `final_differs` | Job result | A [review cut](https://app.flaghand.com/docs/approvals#review-cuts-approve-once-attach-the-final) is waiting. `final_pending`: for its final, or for the match. `final_differs`: the final didn't verify as the same video, so it's the owner's. | `attachFinal` the final, then read `getFinal`. On `final_differs`, send the owner the compare page. Retrying the job doesn't release it. |
| `posting_paused` | 403 / job result | Flaghand paused this workspace's posting under its [Terms](https://flaghand.com/terms#acceptable-use); `rule` names which. Approved jobs are held with their times and approvals; scheduling and requesting approval (`createPost` too), approving, retrying and posting are refused. Drafts, checks, reads, export, cancel and take-down keep working. | Tell the owner what the message says; don't retry or work around it. The owners were emailed. Only Flaghand resumes it: approved posts whose time is still ahead go back on schedule, and the owner retries the rest. |
| `x_app_restricted`, `linkedin_app_restricted`, `tiktok_app_restricted` | 503 / job result | The platform refused Flaghand's own app, which every workspace posts through, not this account's login. The request was refused; earlier thread parts may already be live. A posting job is held with its approval and its connection is not marked expired. | Don't reconnect: it isn't the login. Flaghand is alerted. The owner retries the held job in the desk once the platform lifts it; agents can read its reason but cannot resume it. |
| `tiktok_settings_changed` | Job result | TikTok's settings for the account stopped fitting what the owner approved: who can view it, comments, Duet, Stitch, the video length limit, or the account can't post right now. Nothing was sent; the job is held with this `error_code`, not failed. | Relay the job's reason to the owner. They change it back in TikTok and retry the held job in the desk, or approve it again with TikTok's current settings. Agents can read the reason but cannot resume it. |
| `slideshow_has_clips` | Check result | The TikTok slideshow has video clips, so it can't go out as a photo post. | Make the video from it, then post that file. |
| `connection_login_expired` | 409 / job / connection result | The platform login ended or its renewal was refused. A job is held with its reason, approval and already-posted ids intact, not failed. | Call `startConnection` for the platform and pinned `connection_id`, give the person its `url` and unchanged `for_person` for consent, then wait on `getConnectionAttempt`; Settings is the fallback without `connections` scope. The owner then retries the held job in the desk. Reconnecting alone never replays it, and agents cannot retry it. TikTok attempts that might already have reached TikTok are never resent. |
| `duplicate_post` | Job result | X (403, "duplicate content") or LinkedIn (422, "Content is a duplicate") refused the post because its text repeats one of the account's recent posts. The job failed and isn't retried; a thread's earlier posts stay live. | Change the text (the error names a thread's post) and approve it again; on LinkedIn, a time at least 10 minutes after the earlier post works too. Check flags these repeats before approval with an `edit-text` fix. |
| `upstream_failed` | 502 | The platform (X, LinkedIn or TikTok, or Stripe) didn't answer as expected. | Read the affected resource before retrying. For payPlan, recover the same payment_id; an error alone does not prove no charge occurred. |
| `internal` | 500 | Something went wrong on our side. | Check `/api/v1/status/posting`, then read the affected resource before retrying a write. An error response alone does not prove the write did not happen. |

## Other returned API and job codes

Embedded job, connection and edit errors can arrive in a successful HTTP response. Read `state`, `error_code` and the accompanying message; HTTP 200 does not mean a post succeeded. Agents never approve or resume jobs.

| Code | HTTP / surface | Means | What to do |
|---|---|---|---|
| `connection_account_mismatch` | 409 / connection result | The platform login identifies a different account from the pinned connection. | Reconnect the intended account through its connection link; never switch the destination to make the request succeed. |
| `connection_disconnected` | 409 / job result | A disconnect stopped unsent work; earlier parts may be live. | Reconnect that account and schedule the remainder again. Read live links before drafting anything again. |
| `connection_attempt_invalid` | Connection callback | The sign-in's initiating authority disappeared or changed. | Start a fresh connection attempt from the current workspace; the person completes consent. |
| `connection_cancelled` | 200 connection attempt | The person pressed Cancel or Deny on the platform's consent screen. | Ask the person whether they still want to connect before starting a new link. |
| `connection_failed` | 200 connection attempt | Platform sign-in did not complete. | Call startConnection again and relay its exact URL and for_person; only the person consents. |
| `connection_link_expired` | 200 connection attempt | The connection link expired before consent finished. | Start a fresh connection link for the same intended account. |
| `connection_refresh_pending` | 409 | A Resend login renewal is still unresolved, so nothing was sent. | Try again shortly. If it stays, the owner reconnects Resend in Settings. |
| `connection_refresh_failed` | 429 / 502 | Resend refused to renew the login just now; the login is unchanged and nothing was sent. | Try again shortly. Reconnect Resend in Settings only if it keeps failing. |
| `resend_failed` | Job result | Resend refused the email campaign, or its time passed by more than 2 hours, so it was not sent. | Read the job's `error`, fix what it names, then confirm the campaign again with a new time. Never resend a campaign Resend may have sent. |
| `patreon_by_hand` | Check result | This Patreon draft needs a handoff time or a Post now request. | Choose a handoff time or request Post now. After passkey confirmation, the owner publishes it on Patreon. |
| `patreon_campaign_mismatch` | 409 | The post does not belong to the connected Patreon campaign. | Check the selected campaign and use a post ID or live link from that campaign. |
| `patreon_tier` | Check result | The selected tier is missing or unpublished in the connected Patreon campaign. | Choose a published tier from that campaign, or select Public or Paid members, then check again. |
| `x_allowance_reached` | 409 / job or follow-up result | The workspace's monthly X-post or link-post allowance would be exceeded. | Follow resets_at and next_step: choose a later time or remove the link and schedule it again. A held plug/repost never sends just because the allowance resets. |
| `x_write_unconfirmed` | 409 / job result | X may already have accepted a write; the outcome is uncertain. | Do not retry this publication. Check the account on X. If absent, prepare a new draft for separate approval; follow a message requiring restoration of the original text. |
| `x_subscription_required` | Job / check result | This X post needs a subscription capability that the connected account no longer has. | Shorten it to that account's current capability and schedule it again, or let the owner change their X subscription. |
| `bluesky_video_limit` | Job result | Bluesky's video service said the account can't upload now, usually its daily limit. `error` holds Bluesky's own words. Nothing was sent. | Approve the post again after Bluesky's limit resets, or post without the video. |
| `bluesky_readback_failed` | Live-check result | Bluesky's live post check couldn't be completed, so nothing is verified yet. The post may still be live. | Check again later; do not report the post as verified or send it again. |
| `platform_rate_limited` | Job result | The platform returned HTTP 429 and this request was not resent automatically. | Keep earlier live parts. Choose a new time after the message's reset advice and schedule it again; capacity is not guaranteed at reset. |
| `media_blocked` | Check result | A file's SHA-256 matches an operator block in this workspace. Copying or re-uploading the same bytes stays blocked. | Replace it with the correct reviewed file, check the draft again, and schedule it again. Never bypass the block. |
| `media_deleted` | Job result | Media was deleted before this attempt could use it. | Remove the reference or upload the file again, then check and schedule it again. |
| `approval_refused` | Job result | A final pre-send check refused the approved snapshot. | Read the refusal and fix the draft; obtain a new owner approval, never bypass the check. |
| `linkedin_edit_not_sent` | Edit result | LinkedIn could not be reached before the edit was sent. | The owner may approve the edit again later. |
| `linkedin_edit_refused` | Edit result | LinkedIn refused the edit; the old text remains, or the post was removed. | Read http_status and message. Check the post; the owner can approve again later or edit on LinkedIn. |
| `linkedin_edit_uncertain` | Edit result | LinkedIn did not confirm whether the edit took effect. | Do not resend or overtake it with another edit. Check and edit the post on LinkedIn. |
| `linkedin_readback_unavailable` | Live-check result | The app's member grant cannot read the accepted LinkedIn post/edit back. | Check the post on LinkedIn; do not report its text as verified or resend it. |
| `bad_signature` | 400 webhook | The payment webhook signature did not verify. | The webhook sender must use the configured endpoint and signing secret; callers must not bypass signature verification. |
| `rate_limited` | 429 sign-up | The existing sign-up service's request allowance was reached. | Respect Retry-After (60 seconds), then retry the same sign-up; do not create parallel requests. |
| `signup_rate_limit_unavailable` | 503 sign-up | The sign-up admission service could not answer. | Wait Retry-After (60 seconds), then retry; do not interpret this as an account refusal. |
| `not_configured` | Connection | The platform's server-side sign-in configuration is unavailable. | Wait for the operator to restore configuration; do not change the person's credentials. |
| `read_failed` | Automation result | An X collection read failed without a more specific owned code. | Read the automation and posting status before retrying; do not resend a publication. |
| `response_contract` | Watch result | X returned a response that could not be safely interpreted. | Keep the existing watch; wait for a successful collection and do not treat the missing data as an empty result. |
| `connection_expired` | Watch result | The collector could not use the connected account's login. | Reconnect the intended account, then read the watch status again. |
| `disabled` | Watch result | Collection is not enabled or its required configuration is unavailable. | Read listWatches.enabled; wait for the operator to restore collection rather than creating duplicate watches. |
| `removed` | Watch result | The watched account became protected or was removed by compliance data. | Stop collecting it; do not recreate a watch to bypass the removal. |
| `history_gap` | Watch result | An unfinished collection fell outside X's recent-search window. | Report the coverage gap; continue current collection without claiming the missing period was read. |
| `partial_response` | Watch result | X returned some results with errors, so the page is incomplete. | Keep the watch and wait for collection to recover; do not present the partial page as complete. |
| `attempt_stopped` | 409 / job attempt | The job was ended or approved again before this attempt sent anything; nothing more was sent from it. | Read the job's current state; follow the newer approval or outcome, and do not retry the stopped attempt. |
| `connection_required` | Check result | The draft's platform needs a chosen connected account and none is set, or the chosen one was removed. | Set `connection_id` with `updateDraft` to the intended connection; a missing choice is never filled with another account. |
| `opening` | checkHook check (advisory) | Whether the first line fits the platform's usual preview; `ok: false` is advice, not a refusal. | Move the useful first line up or shorten it, then check again if you want; nothing is blocked. |
| `length` | checkHook check (advisory) | The post's length as the platform counts it; `ok: false` means it exceeds the platform's post length. | Shorten the text to the counted limit before creating the draft. |

| `pinterest_business_account` | 200 connection attempt | The Pinterest account is a personal account; only business accounts can be connected. | Ask the person to switch to a business account in Pinterest's settings (free), then start a new connection link. |

| Code | HTTP / surface | Means | What to do |
|---|---|---|---|
| `pinterest_board_required` | Check result | The draft names no board, or a board chosen for another connection. There is no default. | Call `listPinterestBoards`, ask which board, set `board_id`. |
| `pinterest_board_missing` | Check result / held job | Pinterest has no such board for this account, it can't be saved to, or it didn't answer. | Choose another board. A held job: cancel it, change the draft and schedule it again. |
| `pinterest_section_missing` | Check result | That board has no such section. | Call `listPinterestBoardSections`, or leave `section_id` out. |
| `pinterest_title_length`, `pinterest_description_length`, `pinterest_alt_length`, `pinterest_link` | Check result | Text is over Pinterest's limit, or the link isn't a whole web address. `pinterest_link` on a job: Pinterest refused the link. | Shorten or fix it, then check again. On a failed job, read `result.pinterest.pinterest_said`. |
| `pinterest_media`, `pinterest_image_count`, `pinterest_video_format`, `pinterest_video_duration` | Check result | A file is the wrong type, count or length for this Pin, or it's missing. `pinterest_media` on a job: Pinterest refused the Pin. | Change the media, then check again. |
| `pinterest_cover_seconds`, `pinterest_cover_past_end` | Check result | Pinterest picks the cover frame in whole seconds, and this frame isn't one or is past the video's end. | Use the value in the problem's text, or a cover image. |
| `pinterest_business_account` | Connection attempt / check result / held job | Flaghand posts to Pinterest business accounts, and this one is personal. | Ask the person to switch it in Pinterest's settings. Never retried on its own. |
| `pinterest_disabled` | Check result | Pinterest isn't enabled in this workspace. | Nothing an agent can change. |
| `pinterest_processing` | Job result | Pinterest couldn't process the video. | Check the file plays, upload it again and schedule it again. |
| `pinterest_uncertain` | Job result | The create got no clear answer, so the Pin may exist. Flaghand never sends it again. | Check the board on Pinterest; `result.pinterest.candidates` lists possibilities. To send it anyway, change the draft and schedule it again. |
| `pinterest_failed` | Job result | The approved Pin couldn't be sent: the account changed or was disconnected. | Read the error text, reconnect if needed and schedule it again. |


| Code | HTTP / surface | Means | What to do |
|---|---|---|---|
| `youtube_quota` | Job result | YouTube's daily upload quota is used up; the job stays scheduled. | Wait: it retries just after 12:00 AM Pacific, when the quota resets. Do not resend. |
| `youtube_unconfirmed` | Job result | YouTube may already have the upload or reply, but never confirmed it; it is never sent again on its own. | Ask the person to check the channel in YouTube Studio; if absent, make a new draft and request fresh approval. |
| `youtube_by_hand` | Check result | Apps can't post to YouTube's Community tab; the owner posts this one by hand, so it can't have a posting time. | Request approval without a time; the owner posts it on YouTube. |

## CLI and MCP tool codes

These supplement the API codes above; no HTTP status means the client refused before receiving an API response.

| Code | HTTP / surface | Means | What to do |
|---|---|---|---|
| `usage` | CLI exit 2 | The command, flag or argument is invalid. | Fix the named argument using the command's --help. |
| `network` | Client, no HTTP status | The request or response could not be transferred or decoded. | Check the app origin and connectivity. Retry reads; for writes reuse the advised Idempotency-Key, or read current state first. |
| `invalid_response` | Client wait | A polling response lacks the expected resource or shape. | Check the configured origin and client version, then read the resource directly before resuming the wait. |
| `file_conflict` | Local sync | A file is invalid, duplicated, changed during sync or conflicts with a remote draft. | Read the named file and current remote draft; reconcile explicitly before syncing again. |
| `sync_busy` | Local sync | Another sync owns this directory's lock. | Let that sync finish. If it crashed, confirm no sync is active before removing its stale lock. |
| `workspace_conflict` | Local sync | This directory or draft belongs to a different workspace. | Use the original workspace or a separate sync directory; never upload one workspace's data into another. |
| `wrong_operation_tool` | MCP tool | A read was sent to the write dispatcher or vice versa. | Send the same operation and arguments to the dispatcher named in the message; getOperation describes it. |
| `http_<status>` | CLI/MCP HTTP fallback | The server returned an HTTP error without a structured code (for example http_502). | Inspect the status and message, verify the origin, obey Retry-After, re-authenticate for 401, and read state before retrying a write. |

## MCP JSON-RPC codes

Tool execution errors are MCP results with `isError: true` and the string codes above in `structuredContent.error`; these numeric codes belong to the protocol envelope instead.

| Code | HTTP / surface | Means | What to do |
|---|---|---|---|
| `-32700` | 400 HTTP / stdio | The request body or input line is not JSON. | Send valid JSON; stdio takes one JSON-RPC message per line. |
| `-32600` | JSON-RPC | The envelope is not a JSON-RPC 2.0 request. | Send jsonrpc: 2.0, a string method and a request id when expecting a reply. |
| `-32601` | 404 route / JSON-RPC | The path or method is not supported. | POST to /mcp and use the methods and tools advertised by discovery. |
| `-32602` | JSON-RPC | A tool name, prompt or its parameters is invalid. | Read tools/list, prompts/list or getOperation and fix the name/arguments. |
| `-32603` | 500 / JSON-RPC | An unexpected server failure prevented a safe answer. | Check posting status and read the affected resource before retrying a write. |
| `-32000` | 405 HTTP | This MCP transport does not accept the HTTP method. | POST JSON-RPC messages; no stream/session needs opening or ending. |
| `-32001` | 401 HTTP | The token is missing, invalid or revoked. | Follow WWW-Authenticate to reconnect by OAuth, or supply a current workspace token. |
| `-32002` | JSON-RPC resource | The requested resource is unavailable. | Read resources/list and request a current URI with the required workspace access. |
| `-32003` | 421 HTTP | This is Flaghand's old workers.dev address, which no longer serves MCP; `data.code` is `wrong_host` and `data.origin` names the app. | Connect to `https://app.flaghand.com/mcp`; the same token works there. |

## OAuth and auth.md protocol codes

These endpoints preserve their standard `{error, error_description, error_uri}` body rather than nesting the code. Consent refusals can be returned in the registered redirect URL. API codes above may also pass through auth.md with this shape.

| Code | HTTP / surface | Means | What to do |
|---|---|---|---|
| `server_error` | 500 OAuth | A server failure prevented completing the protocol request. | Retry later after checking service status; retain the same intended account and do not log credentials. |
| `invalid_client_metadata` | 400 / 413 registration | Client metadata is invalid or too large. | Fix the field named in error_description and register again. |
| `invalid_redirect_uri` | 400 registration | A return URI is missing or invalid. | Register the exact supported return URI; do not loosen validation. |
| `invalid_client` | 401 token | Client identification or authentication failed. | Use the registered client id and authentication method, or register the client again. |
| `invalid_grant` | 400 token | A code/assertion expired, was used, was revoked or does not match PKCE/client/redirect data. | Begin fresh sign-in with a new PKCE verifier; for auth.md restart registration when its assertion is no longer valid. |
| `invalid_target` | 400 / consent redirect | The requested resource is not this MCP resource. | Use the resource URL in authorization-server/protected-resource discovery. |
| `unsupported_grant_type` | 400 token | The requested grant is not supported. | Use an advertised grant; there is no refresh-token grant. |
| `unsupported_response_type` | Consent redirect | Authorization requested something other than a code. | Request response_type=code with S256 PKCE. |
| `access_denied` | Consent redirect | The owner declined access. | Stop. Do not retry consent automatically or act as if access was granted. |
| `anonymous_not_enabled` | 400 auth.md | Anonymous workspaces are not supported. | Register with the person's login_hint and let them claim the account. |
| `issuer_not_enabled` | 400 auth.md | No trusted ID-JAG issuer is configured. | Use the advertised login_hint registration and claim flow instead. |
| `invalid_login_hint` | 400 auth.md | The person's email is absent or invalid. | Fix login_hint; never guess another person's identity. |
| `invalid_claim_token` | 404 auth.md | The claim credential does not identify a registration. | Use the exact private claim credential or start a new registration. |
| `claimed_or_in_flight` | 409 auth.md | This registration was already claimed or is being claimed. | Continue the existing claim/sign-in flow; do not create another account or bypass it. |
| `claim_expired` | 410 auth.md | The registration claim link expired. | Start fresh registration for the same person. |
| `authorization_pending` | 400 auth.md token | The person has not finished claim/consent or approved token reissue. | Relay the supplied verification URL with its `user_code`, or the approval URL, unchanged, then poll after interval; never approve for them. |
| `expired_token` | 400 auth.md token | The claim's collection period ended. | Register again and let the person complete the new claim. |

### Provider-owned codes and coverage

TikTok's `refused.code`, `fail_reason` and connection-probe `error_code`, and payment `stripe_code`, can contain provider-defined codes. They are not a finite Flaghand enum: preserve their accompanying message, stop on a refusal, reconnect only when instructed, and check the resource before attempting another write. Do not treat an unknown provider code as permission to retry. Draft check/suggestion codes have their fixes in `problems` and are not error-envelope codes. Legacy string errors retain their message and next_step.

Run `node tools/error-catalog.mjs` for the source-to-docs list with source locations and missing entries. The focused `tests/error-catalog.test.mjs` also checks the generated OpenAPI enum, shared error constants, stored job codes, local errors and JSON-RPC/protocol producers against these tables. A new returned code needs a meaning and a next action here.

## Sign-up and existing accounts

`startSignup` does not return `account_exists`: new, pending and existing emails receive the same `201` response
with a fresh `signup_url`, `user_code` and `claim_code`. Give the person that link with `for_person`, which ends with
the code, and keep the claim code private. A new owner creates their account and types no code; an existing owner
signs in using a configured method, types the code and explicitly allows the agent, with the four OAuth scopes shown
on the page. A missing or wrong code answers `403 user_code_mismatch` and allows nothing; an expired link answers
`409 challenge_expired` first. `claimSignup` stays `202 pending` until then and returns the token. Write that
answer to a private file before printing anything. After that, the claim code alone never issues the token again.
Within 7 days of the passkey or Allow, a claim with the current token as `Authorization: Bearer` returns the same
`token_id` with a new secret and stops the earlier one. Without it, the claim answers `202` with
`next_step: "owner_approves_reissue"`: give the person `approve_url` (a workspace owner signs in and taps Reissue), then
claim with `claim_code` and `reissue_code`. The current secret keeps working until then. `409 conflict` can mean access
was revoked or changed during collection, a newer request replaced that `reissue_code`, or the earlier token cannot be
linked to this sign-up. Follow its message: send the current token, ask the person to approve a new link, or start
again with the same email and the person's sign-in, the new link's code and Allow.
If another pending link already created the account, keep this link and use its sign-in choice; do not add a second
passkey. A failed or canceled passkey does not allow the agent. [Setup](https://app.flaghand.com/docs/setup.md) has the full flow.

## A sandbox or network failure is not an API refusal

For chat apps, a failed fetch or code-runner `CONNECT 403` is that app's own tool, not a Flaghand API response.
Use the OAuth connector; do not ask the person to change network or environment settings or open claude.ai/code.
The network guidance below is only for shell/HTTP clients.

A CLI `network` error happens in the client and has no server HTTP status. `EAI_AGAIN`, `ENOTFOUND` or a failed
connection can be ordinary DNS/connectivity trouble or a sandbox restriction. Claude Code cloud's `403` with
`x-deny-reason: host_not_allowed` identifies its network policy; a bare `403` does not. See
[client network settings and the exact request to give your person](https://app.flaghand.com/docs/setup.md#if-you-cant-reach-flaghand-shellhttp-clients-only).

The JSON codes above, including `signup_closed`, `scope_missing`, `owner_session_required` and `workspace_inactive`,
are Flaghand API decisions: changing a sandbox allowlist does not fix them. The MCP OAuth challenge below is also
an app response, not a network block. Do not disable a policy, replace the host, or send credentials to a proxy to
work around a refusal.

## Remote MCP sign-in errors

Without a token, `/mcp` answers HTTP 401 with JSON-RPC code `-32001` and keeps its `WWW-Authenticate` OAuth
challenge. **Chat apps: add `https://app.flaghand.com/mcp` as an OAuth connector first.**
The connector's sign-in page creates the account free with Google or an email link or code, no card; return and click Allow,
then draft.
No separate site sign-up, no shell, no network or environment settings. A chat app's failed fetch or code-runner
`CONNECT 403` is its own tool, not a Flaghand API response; use the connector, not Claude Code or claude.ai/code.
[Pick your path](https://app.flaghand.com/docs/setup.md#pick-your-path) has the app's click path.

**Shell/HTTP clients:** connect by OAuth or send `Authorization: Bearer tok_…`.
With no account, start with `POST https://app.flaghand.com/api/v1/signup` and
`{"email":"person@example.com"}`; [HTTP setup](https://app.flaghand.com/docs/setup.md#1-an-account-and-access-to-it) explains the person's passkey step
and how to collect the agent's token. Neither call needs a token.

Unknown `/mcp/…` paths return JSON-RPC errors with HTTP 404 and point back to `/mcp`; wrong authenticated methods
return 405 and tell you to POST. Unexpected server failures return HTTP 500 with JSON-RPC code `-32603`, not HTML or
an exception message. Read the affected resource before retrying a write. Preview-media errors also return JSON and
explain how to obtain a current URL. API and MCP fallback errors stay JSON even with `Accept: text/html`.

GNU wget 1.25 discards HTTP 401 response bodies during its authentication handling, even with `--content-on-error`.
It still receives the JSON content type and OAuth `WWW-Authenticate` challenge. Use curl or a fetch/HTTP library to
read that error body; do not change the user agent or remove the challenge.

## An outage, or this post?

Before retrying a failed or late post, read [https://flaghand.com/status](https://flaghand.com/status), or its JSON at https://flaghand.com/status.json
(also `GET /api/v1/status/posting`, no token; MCP `getPostingStatus`). For every workspace together, it shows whether
the scheduler is running, how the last hour's due posts went and how many posting calls to X, LinkedIn and TikTok went
through. When its `state` is `running` and that platform's calls are going through, the failure is the post's own: act on
its `error_code` above. When it's `delayed` or `stopped`, or that platform's calls are failing, it's an outage: scheduled
posts go out when the scheduler runs again (a post more than 2 hours late fails instead), and a failed post can be
approved again once the platform recovers. Nothing failed is sent again on its own. `x_credits_exhausted` means X posts
are held until Flaghand tops up its X API balance.

## Local CLI and stdio MCP errors

These can happen before a request reaches the server, so they have no HTTP status:

- `network`: check `FLAGHAND_URL` (or CLI `--url`) is the app's origin, without `/api/v1`, and that the server is running.
  A read can be retried. A write may already have completed even without its response. When the message names an
  Idempotency-Key, send the same command again with that key (`--idempotency-key`, or `idempotency_key` in MCP): it
  answers what the first one did and makes nothing twice. Otherwise read the current state before retrying. The same
  URL environment variable configures stdio MCP. The same code covers an answer that broke off after it started
  arriving, and an answer whose JSON can't be read (usually a URL that isn't the app's origin).
- `invalid_request` when a local file cannot be read: use a readable path on the machine running the CLI or MCP server.
  Relative paths start at that process's working directory, not at the document or chat containing the command.
- `invalid_request` naming `data_base64` (the remote MCP server answers it too): send the file's bytes as standard
  base64 (`A-Z`, `a-z`, `0-9`, `+` and `/`, padded with `=`), without a `data:` prefix, or, with the local CLI or MCP
  server, the file's path as `file`.
- `invalid_request` saying a number reads as infinity: a JSON number too large for a double (`1e999`) can't be sent. The
  remote MCP server and the API refuse it the same way.
- `wrong_operation_tool` (stdio and remote MCP): a read went through `callWriteOperation` or a write through
  `callReadOperation`. Send the same `operation_id` and `arguments` to the tool the message names; `getOperation` lists
  each operation's dispatcher.
- `usage` (CLI exit 2): fix the command or flag named in the sentence; `flaghand <resource> <action> --help` lists its
  arguments. API refusals and connection failures exit 1. A completed `drafts check` exits 0 even when `ok` is false:
  read `ok` / the listed problems before scheduling.

The local desk's original API (`/api/*` without `v1`) keeps its own `{ "error": "…" }` shape until the desk moves onto
`/api/v1`.
