---
description: "HardBasis API errors: the HTTP status map and the closed ErrorCode set, which codes are retryable, and why to match on code, not prose."
---

# Errors

Every non-2xx body is `{"error": "<human message>", "code": "<machine code>"}`
(the `428` confirmation response carries a few extra fields). **Match on
`code`, never on the prose**: the message may change; the code will not.

`code` is drawn from a **closed enum** that evolves additively: a new refusal
class adds a member, but no member is ever renamed or removed (a contract test
fails CI on a break). So a client can safely switch on it, and an unknown code
means a newer server, so handle it as a generic failure and don't crash.

## Status codes

| status | meaning                                                                                       |
| ------ | --------------------------------------------------------------------------------------------- |
| `400`  | validation / insufficient balance or margin                                                   |
| `401`  | missing or unknown key                                                                        |
| `403`  | compliance refusal, insufficient scope, or a program refusal                                  |
| `404`  | unknown market / order / account, or a route not served here                                  |
| `409`  | idempotency or uniqueness conflict                                                            |
| `428`  | confirmation required (first-seen withdrawal destination)                                     |
| `429`  | rate limited (see [Rate limits](/api/rate-limits))                                            |
| `501`  | feature not wired for this deployment                                                         |
| `503`  | deposits halted (never affects withdrawals) or a transient or deployment-level unavailability |

## The code vocabulary

The full set, from the spec's `ErrorCode` enum (the [REST
reference](/api/reference/) links it, and `/openapi.json` carries it verbatim):

<!-- hb:errors-table:start (generated from x-hardbasis-errors) -->

| code                                                                  | status       | retryable |
| --------------------------------------------------------------------- | ------------ | --------- |
| <span id="body_too_large"></span>`body_too_large`                     | `413`        | no        |
| <span id="compliance_refused"></span>`compliance_refused`             | `403`        | no        |
| <span id="confirmation_required"></span>`confirmation_required`       | `428`        | no        |
| <span id="conflict"></span>`conflict`                                 | `409`        | no        |
| <span id="deposits_halted"></span>`deposits_halted`                   | `503`        | yes       |
| <span id="feature_unavailable"></span>`feature_unavailable`           | `501`        | no        |
| <span id="idempotency_key_reused"></span>`idempotency_key_reused`     | `409`        | no        |
| <span id="insufficient_balance"></span>`insufficient_balance`         | `400`        | no        |
| <span id="insufficient_margin"></span>`insufficient_margin`           | `400`        | no        |
| <span id="insufficient_scope"></span>`insufficient_scope`             | `403`        | no        |
| <span id="internal"></span>`internal`                                 | `500`        | no        |
| <span id="market_halted"></span>`market_halted`                       | `400`, `409` | no        |
| <span id="not_found"></span>`not_found`                               | `404`        | no        |
| <span id="oi_cap"></span>`oi_cap`                                     | `400`, `409` | no        |
| <span id="oracle_stale"></span>`oracle_stale`                         | `400`, `409` | no        |
| <span id="position_limit"></span>`position_limit`                     | `400`, `409` | no        |
| <span id="rate_limited"></span>`rate_limited`                         | `429`        | yes       |
| <span id="reduce_only"></span>`reduce_only`                           | `400`, `409` | no        |
| <span id="referral_forbidden"></span>`referral_forbidden`             | `403`        | no        |
| <span id="session_limit"></span>`session_limit`                       | `403`        | no        |
| <span id="size_not_whole_contracts"></span>`size_not_whole_contracts` | `400`        | no        |
| <span id="token_rail_unavailable"></span>`token_rail_unavailable`     | `503`        | no        |
| <span id="tvl_cap"></span>`tvl_cap`                                   | `409`        | no        |
| <span id="unauthorized"></span>`unauthorized`                         | `401`        | no        |
| <span id="unavailable"></span>`unavailable`                           | `503`        | yes       |
| <span id="usdhb_capacity"></span>`usdhb_capacity`                     | `409`        | no        |
| <span id="usdhb_dust"></span>`usdhb_dust`                             | `409`        | no        |
| <span id="usdhb_mints_halted"></span>`usdhb_mints_halted`             | `409`        | no        |
| <span id="usdhb_oracle_stale"></span>`usdhb_oracle_stale`             | `409`        | no        |
| <span id="usdhb_quote_expired"></span>`usdhb_quote_expired`           | `409`        | no        |
| <span id="usdhb_requote"></span>`usdhb_requote`                       | `409`        | no        |
| <span id="usdhb_whole_units"></span>`usdhb_whole_units`               | `409`        | no        |
| <span id="validation"></span>`validation`                             | `400`        | no        |

<!-- hb:errors-table:end -->

The status a given code rides can vary with context; the code is the stable
signal. Build against `code`. A `retryable` code means the identical request
may succeed later (back off first; honor `Retry-After` on a `429`); every
other code needs a changed request or a changed account state. The table is
generated from the spec's `x-hardbasis-errors` map in `/openapi.json`, which
carries the same statuses and retry flag per code.
