Error handling
RFC 9457 problem+json, field errors, Retry-After and rate-limit headers.
Every non-2xx response is an RFC 9457 problem document with the media type
application/problem+json. One shape, everywhere.
The problem shape
This is the body POST /v1/documents sends for a credit note (NC) that has no
informacionReferencia:
{
"type": "https://sello.cr/problems/validation",
"title": "Invalid document request",
"status": 422,
"detail": "The document failed validation. See errors[] for details.",
"errors": [
{
"path": "informacionReferencia",
"message": "NC requires at least one informacionReferencia.",
"code": "invalid_value"
}
]
}https://sello.cr/problems/validation is the type of a body that fails the
request schema on POST /v1/documents. The other routes' schema refusals are
still about:blank, so do not branch on validation anywhere else.
type— a URI identifying the problem class (defaults toabout:blank). Branch on it, not ontitle.title— short, human-readable summary of the problem type.status— the HTTP status code.detail— explanation specific to this occurrence.instance— URI of this specific occurrence. Most responses omit it.errors— a Sello extension: an array of per-field validation problems (path+message+code), populated for validation failures. Branch oncode(required,invalid_type,invalid_format,out_of_range,unknown_field,invalid_value, or the domain refusal's own name), never onmessage; Changelog / Versions lists the vocabulary.
Status codes you'll see
| Status | Meaning |
|---|---|
400 | Malformed request. On the five list routes (GET /v1/documents, GET /v1/received-documents, GET /reference/cabys and their portal twins), a query parameter the route does not accept is a 400 with type urn:sello:problem:unknown-query-parameter: errors[] holds one entry per unknown key (path is the key, case-sensitive), and no value is echoed. It is never ignored, and it comes before any 422 for the parameters the route does accept. |
401 | Missing, invalid, or revoked API key. |
403 | Authenticated but not allowed (e.g. cross-emisor access, an emisor-pinned key listing with another emisor's emisorId, or a key without the permission the operation needs — insufficient-permission). |
404 | Not found, or scoped out (a cross-tenant clave reads as 404). An emisor that is not in your account reads as 404, the same as one that does not exist. A path no route matches is 404 with type https://sello.cr/problems/route-not-found. |
405 | The /v1 or /reference path exists, but not for this method (https://sello.cr/problems/method-not-allowed). The Allow header lists the methods it does take. |
409 | On POST /v1/documents, one of seven types: idempotency-key-conflict (the key was used with a different body; permanent, pick a new key), idempotency-result-expired (the key already completed this same request and its original response has expired; permanent, the key stays spent, read the document through the documents API), duplicate-document (permanent), idempotency-in-flight and issuance-reservation-lost (both transient; retry after Retry-After), consecutivo-series-exhausted, and consecutivo-already-issued (the emisor's counter is behind its series; emisorId and numeroConsecutivo name the number, nothing was written, and retries are refused until Sello advances the counter). Elsewhere, a conflicting Mensaje Receptor kind. |
412 | A Sello-Replay-Only create found no settled result under the key (idempotency-replay-miss) — nothing was issued. See Idempotency. |
413 / 415 | Payload too large / unsupported media type. A document body is limited to 2 MiB. |
422 | Validation failed — inspect errors[]. This includes an unknown field anywhere in the body, named in errors[].path. |
429 | Rate limited. Wait Retry-After seconds; RateLimit-* tells you the account's budget. |
Insufficient permission
A key that lacks the permission an operation needs gets 403 with
type: https://sello.cr/problems/insufficient-permission. The body names the
missing permission in requiredPermission (one of documents:read,
documents:write, received-documents:read, received-documents:write,
webhooks:write). Nothing was spent. Do not retry with the same key: use a key
that holds the permission. See
Authentication.
Retry-After
Every 429 carries a Retry-After header: the seconds until you may retry.
Some transient 409s and 5xxs carry one too. Honor it. The SDK's transport layer
retries retryable 5xx/429 automatically, backing off and respecting
Retry-After, before any non-2xx is surfaced to your code.
Rate-limit headers
A response the per-account limiter counted carries the account's budget. Every key of an account draws on that one budget:
| Header | Value |
|---|---|
RateLimit-Limit | Requests the account may make per window, across all its keys. |
RateLimit-Remaining | Requests left in the current window. |
RateLimit-Reset | Seconds until the window resets. |
/v1 and /reference draw from the same budget. The headers are a hint: a
request refused before the key is checked, a per-IP 429, and some 503s
carry none. The count is shared by every server, and falls back to a
per-server count while the shared store is unreachable. Retry-After on a
429 is the header to obey.
Typed errors in the SDK
The SDK parses the problem body for you. Every non-2xx (after retries are
exhausted) throws a SelloApiError exposing .status, the parsed .problem
(type / title / status / detail / instance), and .errors (the
field-level extension):
import { SelloApiError } from '@magiios/sdk';
try {
await sello.documents.create(invalidInvoice, `order-${order.id}:FE`);
} catch (err) {
if (err instanceof SelloApiError) {
console.error(err.status, err.problem.title, err.problem.detail);
for (const fieldError of err.errors) {
console.error(` ${fieldError.path}: ${fieldError.message}`);
}
}
}Retries are unchanged by this: retryable 5xx/429 are retried by the
transport layer first; only a final non-2xx becomes a SelloApiError.