# Errors

> The error format, every published code, and why a connection needs the user.

Every error from the API has the same shape. Branch on `error`, the code; show or log `message`, which may change. `request_id` is also in the `Sidelatch-Request-Id` header. A failed [run](https://sidelatch.com/docs/concepts#runs) adds its `run_id`.

**Error body**

```json
{
  "error": "reconnect_needed",
  "message": "The portal no longer accepts the stored login...",
  "reason": "wrong_password",
  "run_id": "run_5d1e...",
  "request_id": "req_9b2f..."
}
```

Each code has an owner, which says whose move it is: **you** (change the request), the **user** (they have to sign in again or answer a step), the **portal** (down, slow or changed), or **Sidelatch** (ours; retry and send us the request id).

| Code | Status | Whose move | What it means |
|---|---|---|---|
| `invalid_api_key` | 401 | You | The API key is missing, wrong or revoked. |
| `read_only_key` | 403 | You | This API key can only read. Use a read_write key. |
| `invalid_request` | 422 | You | The request body or a parameter is not valid. detail lists each problem. |
| `bad_params` | 400 | You | The operation's params are not valid. message says which. |
| `unknown_operation` | 404 | You | This portal has no operation by that name. See GET /v1/portals. |
| `unknown_portal` | 404 | You | No portal by that name. See GET /v1/portals. |
| `portal_not_enabled` | 403 | You | This portal is not turned on for your account. |
| `not_found` | 404 | You | No such resource, or it belongs to another account. |
| `not_an_upload` | 400 | You | This operation does not take a file. Use /run. |
| `file_too_large` | 413 | You | The file is over the upload limit (max_bytes). |
| `idempotency_key_reused` | 422 | You | This Idempotency-Key was already used for a different request. |
| `idempotency_in_progress` | 409 | You | A write with this Idempotency-Key is still running, or its outcome is unknown. Read the portal (or the run) before trying again with a new key. |
| `connection_read_only` | 403 | You | The user linked this connection read-only, so it takes no writes. Relink it with a link token that has "writes": true to ask the user for more. |
| `not_enabled` | 400 | You | This feature is not turned on for this server or account. |
| `plan_limit` | 403 | You | Your plan doesn't include this. message says which limit; upgrade is where to upgrade. |
| `rate_limited` | 429 | You | Too many calls. Wait retry_after seconds. scope says which limit. |
| `conflict` | 409 | You | The request conflicts with the current state. message says how. |
| `bad_request` | 400 | You | The request could not be used. message says why. |
| `forbidden` | 403 | You | This account or key may not do that. |
| `portal_in_use` | 409 | You | Connections still use the portal this build made. Delete those connections first, then delete the build. |
| `run_not_finished` | 409 | You | The run is still queued or running. Poll again. |
| `reconnect_needed` | 409 | The user | The portal no longer accepts the stored login. Ask the user to sign in again through the connect window; the connection id stays the same. reason says why when it is known. |
| `auth_failed` | 401 | The user | The portal rejected the username, password or code the user entered. |
| `challenge_failed` | 401 | The user | The answer to a sign-in challenge was wrong or ran out of tries. |
| `link_expired` | 400 | The user | The link token or sign-in step expired or was already used. Start again with a new link token. |
| `locked_out` | 429 | The user | Too many failed sign-ins. We stop before the portal locks the account. Try again later. |
| `login_blocked` | 422 | The user | The portal wants a check that only a person on its own page can pass. |
| `session_refused` | 400 | The portal | The user signed in, but the portal refused Sidelatch's reads with that session (often a bot check on the portal's side). Nothing was saved. |
| `portal_down` | 503 | The portal | The portal is not responding. Retry later. |
| `portal_busy` | 503 | The portal | The portal asked us to slow down, or its request budget is spent. Wait retry_after seconds. |
| `schema_drift` | 502 | The portal | The portal changed what it returns. We are alerted and repair the connector. |
| `browser_busy` | 503 | Sidelatch | Every hosted sign-in browser is in use. Try again in a minute. |
| `unavailable` | 503 | Sidelatch | Part of the service is not available right now. Retry later. |
| `timeout` | 504 | Sidelatch | The call did not finish in time. Nothing is retried for you; run it again, or use an async run. |
| `internal_error` | 500 | Sidelatch | Something went wrong on our side. Retry later and send us the request id. |

### Why a connection needs the user

`reconnect_needed`, the `connection.reconnect_needed` event and `GET /v1/connections` all carry a `reason`.

| Reason | Meaning |
|---|---|
| `wrong_password` | A full sign-in with the stored login was refused. The user changed their password, or the account is locked. |
| `session_rejected` | The portal stopped accepting the saved session and there was no way to renew it. |
| `challenge_required` | Signing in again needs a step only the user can answer (a texted code, a phone approval, a CAPTCHA). |
| `portal_blocked` | The portal put up a check that only a person on its own page can pass. |

### More on common codes

| Status | Error | What to do |
|---|---|---|
| 409 | `reconnect_needed` | The user's password changed or the portal refused the login. Create a link token for the same user and portal and open the connect window again. The connection id stays the same. |
| 503 | `portal_down` | The portal is down or timing out. Retry later. |
| 503 | `portal_busy` | We are holding back from this portal for a moment: it asked us to slow down, or its request budget is spent. Nothing was sent. Retry after `retry_after` seconds (also in the `Retry-After` header). The connection is fine. |
| 429 | `rate_limited` | You are calling the portal faster than your fair share allows. Nothing was sent. `scope` says which limit: `customer_portal` (your account may use half of each portal's request budget, so one customer can't slow the portal for everyone) or `connection_daily` (each connection makes up to 1,000 portal calls a day, refilling steadily). Retry after `retry_after` seconds, or pass `max_age` to read a recent result: cached reads never count. `GET /v1/usage` shows your limits. |
| 502 | `schema_drift` | The portal changed what it returns. We are alerted and fix the connector. |
| 400 | `bad_params` | Your params don't fit the operation. `detail` says why. |
| 403 | `read_only_key` | The operation writes to the portal and your key is read-only. Use a `read_write` key. |
| 422 | `idempotency_key_reused` | You sent this `Idempotency-Key` with a different request. Use a new key for each write. |
| 404 | `unknown_operation` | The portal has no such operation. |
| 404 | `not_found` | No such record, or no such connection on your account. |
| 401 |  | Missing or unknown API key. |

---

Sidelatch docs: [Docs](https://sidelatch.com/docs.md) · [Quick start](https://sidelatch.com/docs/quickstart.md) · [Concepts](https://sidelatch.com/docs/concepts.md) · [The connect window](https://sidelatch.com/docs/guides/connect-window.md) · [Webhooks](https://sidelatch.com/docs/guides/webhooks.md) · [MCP for AI agents](https://sidelatch.com/docs/guides/mcp.md) · [Writes](https://sidelatch.com/docs/guides/writes.md) · [Build a portal](https://sidelatch.com/docs/guides/build-a-portal.md) · [Events](https://sidelatch.com/docs/events.md) · [Errors](https://sidelatch.com/docs/errors.md) · [API reference](https://sidelatch.com/docs/api.md)
