# API Error Reference — CommsHarbor

Every 4xx or 5xx response under `/api/*` uses **RFC 9457** (`Content-Type: application/problem+json; charset=utf-8`), with a stable `code` and backward-compatible `error` and `message` fields.

## Standard envelope

```json
{
  "type": "https://commsharbor.com/errors#invalid_session",
  "title": "Invalid session",
  "status": 401,
  "detail": "Sign in to an account session on this domain or supply a supported API credential.",
  "instance": "/api/me",
  "code": "invalid_session",
  "error": "invalid_session",
  "message": "Sign in to an account session on this domain or supply a supported API credential."
}
```

- `type`: problem type URI (`https://<host>/errors#<code>`).
- `title`: short summary of the problem type.
- `status`: integer HTTP status code (400–599).
- `detail`: occurrence-specific human explanation.
- `instance`: request pathname without query parameters.
- `code`: stable snake_case machine error code.
- `error` / `message`: backward-compatible aliases of `code` and `detail`.
- Relevant headers: `Retry-After` (429/503), `Allow` (405), and `PAYMENT-REQUIRED` (402 x402).

## Error code catalog

### Authentication & Access

| HTTP | Code | Description |
|---:|---|---|
| 401 | `unauthorized` | **Unauthorized** — Authentication is required or the supplied credential was not accepted. |
| 401 | `invalid_session` | **Invalid session** — Sign in to an account session on this domain or supply a supported API credential. |
| 401 | `account_required` | **Account required** — This operation requires a signed-in account. |
| 401 | `invalid_api_key` | **Invalid API key** — The API key (`mmk_…`) is invalid, revoked, or does not belong to this organization or product. |
| 401 | `invalid_token` | **Invalid token** — The bearer or OAuth token is invalid, expired, or revoked. |
| 401 | `invalid_wallet_token` | **Invalid wallet credential** — The wallet token (`mmw_…`) is invalid or expired. Authenticate the wallet again. |
| 401 | `wallet_proof_required` | **Wallet proof required** — Authenticate the paying wallet (`mmw_…`) to inspect or recover this payment. |
| 403 | `forbidden` | **Forbidden** — Your credential is valid, but it does not grant permission for this resource or action. |
| 403 | `organization_mfa_required` | **Second factor required** — Organization owners and admins must authenticate with a second factor (passkey or authenticator). |
| 403 | `organization_domain_locked` | **Organization domain locked** — This action is restricted by the organization's custom domain policy. |
| 403 | `human_verification_required` | **Human verification required** — Complete the interactive verification or use a paid/authenticated API route. |
| 403 | `bot_blocked` | **Automated crawler blocked** — Automated crawlers, indexers and liveness probes cannot submit this form. |
| 403 | `turnstile_failed` | **Verification failed** — The verification challenge did not succeed. Request a new challenge and try again. |

### Validation & Input

| HTTP | Code | Description |
|---:|---|---|
| 400 | `bad_request` | **Bad Request** — The request is malformed or missing required parameters. |
| 400 | `invalid_request` | **Invalid request** — The request URL, headers, or parameters failed validation. |
| 400 | `bad_json` | **Invalid JSON** — The request body could not be parsed as valid JSON. |
| 400 | `invalid_organization` | **Invalid organization** — Supply a valid organization identifier in X-Organization-Id or the route path. |
| 400 | `name` | **Invalid name** — Provide a valid name within the allowed length. |
| 400 | `email` | **Invalid email** — Provide a valid email address. |
| 400 | `message` | **Invalid message** — Provide a message with the required minimum length. |
| 409 | `conflict` | **Conflict** — The request conflicts with the current resource state or reuses an Idempotency-Key with a different payload. |
| 413 | `payload_too_large` | **Payload too large** — The request body exceeds the maximum size allowed for this route. |
| 413 | `body_too_large` | **Payload too large** — The request payload exceeds the maximum size accepted by this endpoint. |
| 413 | `too_large` | **Payload too large** — The submitted payload exceeds the endpoint size limit. |
| 422 | `unprocessable_entity` | **Unprocessable entity** — The request is well-formed, but one or more field values are semantically invalid. |

### Payment, Credit & Quota

| HTTP | Code | Description |
|---:|---|---|
| 402 | `payment_required` | **Payment required** — Pay per call via x402 (USDC on Base using PAYMENT-REQUIRED / accepts[]) or supply a prepaid credit token in X-Credito. |
| 402 | `payment_verification_failed` | **Payment verification failed** — The submitted x402 payment proof was rejected. Inspect detail and the quoted PAYMENT-REQUIRED terms. |
| 401 | `credito_invalido` | **Invalid credit token** — The prepaid credit token (`cred_…`) is unknown or invalid. |
| 401 | `credito_simulado` | **Simulated credit rejected** — Development test credit tokens are not accepted in production. |
| 402 | `saldo_insuficiente` | **Insufficient balance** — The account or prepaid credit balance is too low for this call. Top up credit or pay via x402. |
| 404 | `not_for_sale` | **Not for sale** — This paid route or SKU is not currently offered on this product. |

### Rate Limits

| HTTP | Code | Description |
|---:|---|---|
| 429 | `rate_limited` | **Too many requests** — Request rate or concurrency limit exceeded. Wait for the duration in the Retry-After header before retrying. |
| 429 | `rate_limit_exceeded` | **Rate limit exceeded** — The free allowance or rate window was exceeded. Wait for the next window, sign in, or pay per call. |

### Resources & Routing

| HTTP | Code | Description |
|---:|---|---|
| 404 | `not_found` | **Not found** — The API route or requested resource does not exist (or is not accessible to your credential). |
| 404 | `nao_encontrado` | **Not found** — The API route or requested resource does not exist (Portuguese-language product code equivalent to not_found). |
| 404 | `organization_not_found` | **Organization not found** — The organization does not exist or your account is not a member of it. |
| 404 | `path_template_nao_expandido` | **Unexpanded path template** — This path contains literal catalog placeholders (such as `{id}`). Replace each placeholder with a concrete value. |
| 405 | `method_not_allowed` | **Method not allowed** — This HTTP method is not accepted on this endpoint. Check the Allow header for supported methods. |
| 408 | `request_timeout` | **Request timeout** — The client did not send the complete request within the server timeout. |
| 408 | `upload_timeout` | **Upload timeout** — The request body was not received within the allowed time window. |

### Server & Availability

| HTTP | Code | Description |
|---:|---|---|
| 500 | `internal_error` | **Internal server error** — An unexpected error occurred while processing the request. Retrying is safe on idempotent routes. |
| 502 | `bad_gateway` | **Bad gateway** — An upstream dependency returned an invalid response. Retry later. |
| 502 | `send_fail` | **Delivery failed** — The upstream delivery service could not complete the request. Retry later. |
| 503 | `service_unavailable` | **Service unavailable** — The service is temporarily unavailable or at capacity. Check Retry-After and try again. |
| 503 | `auth_unavailable` | **Authentication service unavailable** — The shared authentication backend is temporarily unavailable. Retry in a moment. |
| 503 | `mail_cfg` | **Mail transport not configured** — Contact mail delivery is not configured on this instance. |

### Product-specific codes

| HTTP | Code | Description |
|---:|---|---|
| 400 | `cartao_dados` | Invalid card data (`cartao_dados`, with the `campo`). (POST /api/credito/asaas/{id}/cartao) |
| 400 | `cartao_hospedado` | Credit amount outside `pacotes` and `exatos`, amount out of range, invalid CPF/CNPJ, name or email, direct card payload (`cartao_hospedado`), or the gateway refused the payer (`pagador_recusado`, with the reason in `detalhe`). (POST /api/credito/asaas) |
| 400 | `domain_invalid` | Paid without `domain` (`missing_input`) or with a domain that is not public (`domain_invalid`), both with `example`. Not charged. (GET /api/x402/email-check) |
| 400 | `missing_input` | Paid without `domain` (`missing_input`) or with a domain that is not public (`domain_invalid`), both with `example`. Not charged. (GET /api/x402/email-check) |
| 400 | `pagador_recusado` | Credit amount outside `pacotes` and `exatos`, amount out of range, invalid CPF/CNPJ, name or email, direct card payload (`cartao_hospedado`), or the gateway refused the payer (`pagador_recusado`, with the reason in `detalhe`). (POST /api/credito/asaas) |
| 401 | `api_key_retired` | No signed-in session, or the API key is invalid or revoked (`invalid_api_key`); an old `ch_…` key answers `api_key_retired`. (GET /api/context, GET /api/email/workspaces/{id}, GET /api/organizations/{organization_id}, GET /api/organizations/{organization_id}/audit) |
| 403 | `organization_key_required` | The session or key lacks the permission this operation needs (an API key never reaches billing, erasure, exports or the audit trail), an account key was used where an organization key is needed (`organization_key_required`), or an owner/admin has no second factor (`organization_mfa_required`). (GET /api/context, GET /api/email/workspaces/{id}, GET /api/organizations/{organization_id}, GET /api/organizations/{organization_id}/audit) |
| 422 | `cartao_recusado` | Card declined (`cartao_recusado`). (POST /api/credito/asaas/{id}/cartao) |
| 503 | `asaas_ocupado` | Automatic Pix unavailable in this app, the gateway is busy (`asaas_ocupado`, wait `retry_after_s`), or too many charges from people not signed in waiting for payment. (POST /api/credito/asaas) |

## Protocol exceptions

`/mcp` keeps JSON-RPC 2.0, OAuth 2.1 routes follow RFC 6749, and LLM provider proxies under `/v1/*` preserve the upstream provider format.

---

- HTML: https://commsharbor.com/errors
- OpenAPI: https://commsharbor.com/openapi.json
- llms.txt: https://commsharbor.com/llms.txt
- API: https://commsharbor.com/api/
