Guides
Errors and retries
The error shape
Section titled “The error shape”Every error, from every route, is an ApiError:
{ "code": "QUOTE_USED", "message": "This quote is reserved for other accounts; request a new quote", "details": null, "field": "option", "recovery": "requote", "retryAfterSeconds": null, "requestId": "6f1d2c3b-4a5e-4f60-8718-293a4b5c6d7e"}| Field | Meaning |
|---|---|
code |
What went wrong. An open list: new codes can appear. |
message |
For your logs. Don’t parse it: the wording can change. |
details |
Structured detail for some codes, otherwise null. |
field |
The request field at fault, such as send.amount or accounts.payer, or null. |
recovery |
What to do next. A closed list. |
retryAfterSeconds |
When to retry, on a retry error that knows. Otherwise null. |
requestId |
The request’s id, also in the x-request-id header. Quote it when you contact Khalani. |
Act on recovery
Section titled “Act on recovery”Branch on recovery, not on code. It says what to do next for every error, a code you don’t know included:
recovery |
Do this |
|---|---|
fix_request |
Change the request, as field and details say. Sending it unchanged fails again. |
requote |
Request a new quote, and create the order from it. |
retry |
Send the same request again, after retryAfterSeconds when it is set, or with a capped backoff. |
read_order |
Read the order to see where it stands. |
restart_sync |
Sync again with no cursor. |
contact_support |
Contact Khalani with the requestId. |
switch (error.recovery) { case "retry": return retryAfter(error.retryAfterSeconds ?? backoff()); case "requote": return startOver(); case "read_order": return refreshOrder(); case "restart_sync": return syncFromScratch(); case "fix_request": // a bug in your integration, or bad user input in `field` case "contact_support": return fail(error);}Every request is safe to repeat. See Repeating a request.
details
Section titled “details”details is null except on these codes:
| Code | details |
|---|---|
VALIDATION_FAILED from the request’s schema |
issues: each bad field, with its message. |
AMOUNT_TOO_SMALL, AMOUNT_TOO_LARGE |
minAmount and maxAmount: the range that would quote, as AssetAmounts, or null. |
ACTION_UNAVAILABLE |
reason: why the action can’t run, such as TRADING_ENDED. |
Don’t depend on details for VALIDATION_FAILED: some validation errors name only field, and malformed JSON names neither.
Codes by status
Section titled “Codes by status”| HTTP | Codes |
|---|---|
| 400 | VALIDATION_FAILED, UNSUPPORTED_ASSET, UNSUPPORTED_PAIR, ACCOUNT_INVALID, ROLE_MISSING, OPTION_INVALID, INVALID_SIGNATURE |
| 401 | UNAUTHENTICATED: no X-API-Key |
| 403 | FORBIDDEN: the key is unknown or inactive, or your terms can’t be used |
| 404 | NOT_FOUND: no such order of yours, or no such route |
| 409 | QUOTE_USED, REQUOTE_REQUIRED, IDEMPOTENCY_IN_PROGRESS, ACTION_UNAVAILABLE |
| 410 | QUOTE_EXPIRED, CURSOR_EXPIRED |
| 422 | AMOUNT_TOO_SMALL, AMOUNT_TOO_LARGE, ACCOUNT_NOT_ACTIVATED, ACCOUNT_NOT_READY |
| 429 | RATE_LIMITED: over a rate limit. Retry after retryAfterSeconds. |
| 500 | INTERNAL: sending the request again won’t fix it. Contact Khalani with the requestId. |
| 503 | MAINTENANCE, UPSTREAM_UNAVAILABLE, PRICE_UNAVAILABLE, NO_CAPACITY: retry after retryAfterSeconds, or with a backoff. |
Every code
Section titled “Every code”| Code | recovery |
Meaning |
|---|---|---|
VALIDATION_FAILED |
fix_request |
The request doesn’t match the schema, takes a field the route doesn’t, or names an unknown API-Revision. |
UNSUPPORTED_ASSET |
fix_request |
The catalog doesn’t list the asset. Refresh it. |
UNSUPPORTED_PAIR |
fix_request, or requote at order creation |
The two assets can’t trade, such as the same asset on both sides, or the pair stopped trading. |
ACCOUNT_INVALID |
fix_request |
An account is on the wrong chain or isn’t a valid address there. |
ROLE_MISSING |
fix_request |
A role the order needs has no account. |
OPTION_INVALID |
requote |
The option wasn’t issued to your key, or was changed. |
INVALID_SIGNATURE |
fix_request |
The cancel signature isn’t refundTo’s over the cancel message. |
UNAUTHENTICATED |
fix_request |
No X-API-Key header. |
FORBIDDEN |
contact_support |
The key is unknown or inactive, or your terms can’t be used. |
NOT_FOUND |
fix_request |
No such order of yours, or no such route. |
QUOTE_USED |
requote |
The option is reserved for other accounts. |
REQUOTE_REQUIRED |
requote |
Your fees or the order’s deadlines changed since the quote. |
IDEMPOTENCY_IN_PROGRESS |
retry |
The same request is still running. |
ACTION_UNAVAILABLE |
read_order |
The action can’t run on the order now. details.reason says why. |
QUOTE_EXPIRED |
requote |
The quote or the order’s funding window expired before creation finished. |
CURSOR_EXPIRED |
restart_sync |
The sync cursor can’t be used any more. |
AMOUNT_TOO_SMALL, AMOUNT_TOO_LARGE |
fix_request, or requote at order creation |
The size is out of range. details has the range. |
ACCOUNT_NOT_ACTIVATED |
fix_request |
The account must be activated on its chain before it can be paid. |
ACCOUNT_NOT_READY |
fix_request |
The account can’t take the payment, such as an EVM contract that rejects a native coin. |
RATE_LIMITED |
retry |
Over a rate limit. |
INTERNAL |
contact_support |
A server error. |
PRICE_UNAVAILABLE |
retry |
Pricing failed for now. |
NO_CAPACITY |
retry |
Nothing is fillable in this direction now. |
UPSTREAM_UNAVAILABLE |
retry |
A chain or a dependent service can’t be reached now. |
MAINTENANCE |
retry |
Quoting and order creation are paused. |
An error can name a recovery other than its code’s usual one. Follow the error’s.
Getting help
Section titled “Getting help”Contact Khalani through your onboarding channel with the requestId, the order id if there is one, and the time of the call.