Skip to content
API v1 is deprecated. It stays supported, but new integrations should use the Khalani API (v3). See Migrate to v3.
API v1 · Deprecated

Handling exceptions (v1)

Treat errors as part of the user experience: an expired quote, an unsupported pair and a refund are all ordinary outcomes. Check the HTTP status first, then the body.

Most errors are an exception envelope. Branch on name, except server-broadcast failures, which also carry a recovery errorCode:

{
"message": "Quote(quoteId: 3f6c2a1e-8b4d-4e7a-9c15-2d0b7e9a4f61, routeId: Hyperstream) not found",
"name": "QuoteNotFoundException",
"details": { "quoteId": "3f6c2a1e-8b4d-4e7a-9c15-2d0b7e9a4f61", "routeId": "Hyperstream", "code": 0 }
}
Field Type Meaning
message string Human-readable. Log it; do not parse it.
name string The exception. Use it for logic.
details object or array Extra context. Optional, and hidden on some exceptions.
errorCode string Server-broadcast recovery: BROADCAST_REJECTED or BROADCAST_OUTCOME_UNKNOWN.
reasonCategory string Server-broadcast reason before friendly-message mapping. See below.
txHash string Original broadcast identity, when derivable.

A few responses have other shapes:

Source Status Body
Request validation 400 { "message": "Validation failed", "name": "ValidationException", "details": [{ "field", "message", "code" }] }
A body that is not JSON 400 { "message": "Malformed JSON body", "name": "BadRequestException" }
Rate limit (build only) 429 { "errorCode": "RATE_LIMITED", "message": "Too many requests, please retry later" }
Maintenance 503 { "name": "MaintenanceException", "message": "SystemMaintenance" }, with Retry-After: 300
Unknown order in GET /v1/orders/by-id/{orderId} 404 Plain text: Order not found
Unknown path 404 Plain text: 404 Not Found

So read the body as text, then parse it as JSON when you can. Log name ?? errorCode with message, and keep the x-request-id header of every failed response.

  1. A 4xx usually needs a corrected request. For 429, back off and retry. For server-broadcast failures, follow errorCode below even on 400.
  2. A 503 is maintenance. Wait for Retry-After (300 seconds) and retry. Quotes and builds pause together; submits and order reads keep working.
  3. A 500 can be retried with backoff, except a submit that says the deposit was submitted. See the matrix.
  4. An expired or missing quote is not retried. Before any broadcast, quote again and build from the new quote. After a broadcast, follow the recovery rules below before creating another deposit.

For the user, map errors to an action: “Price expired, refresh”, “This token is not supported on that chain”, “Connect the wallet you quoted with”.

If the initial broadcast fails, the API looks up the locally derived hash. A hit continues order creation and returns the ordinary { orderId, txHash }. Otherwise the error preserves its name, message and HTTP status, and adds top-level errorCode, reasonCategory and an optional derivable txHash. Provider details stay hidden.

  • BROADCAST_REJECTED: an explicit outer EVM chain id differs from the requested source, and the failed send was followed by a successful lookup miss. Fix it and re-sign. zkSync/Abstract, undecodable transactions and failed lookups do not produce this code.
  • BROADCAST_OUTCOME_UNKNOWN: the transaction may have been accepted. Look for an existing order first. Retry the same bytes or submit txHash while the quote survives.
reasonCategory Meaning
invalid The local proof required for BROADCAST_REJECTED.
transport HTTP, connection or timeout failure.
duplicate The node recognizes a duplicate or already-processed transaction.
nonce_conflict A nonce is consumed or conflicts with another transaction.
node_policy Node admission policy, such as an underpriced replacement.
current_state Positively recognized funds/fee failure.
unknown Unrecognized error, simulation, account-abstraction or signature failure.

Categories describe the original RPC failure, before friendly text; they do not prove non-acceptance. The precedence is transport, duplicate, nonce conflict, node policy, current state, then unknown.

After an unknown outcome, re-sign only for current_state and no prior broadcast of these bytes anywhere, including the wallet. This must be the first broadcast attempt, not merely the first API request. Duplicate or nonce-conflict categories never authorize re-signing. If you cannot establish that history, preserve the original bytes.

Look up the order with GET /v1/orders/{address} before retrying. Successful submit deletes the quote; otherwise it remains until validBefore plus 60 seconds, capped at 24 hours. Retry the same bytes or submit the original hash within that window. After expiry, contact Khalani with that hash before making another deposit.

With POST /v1/quotes?mode=stream:

  • An invalid body returns an ordinary JSON error, not a stream.
  • A route that fails or does not quote is left out. The stream can have fewer lines than there are routes, or none.
  • The stream ends early when the native route quotes. Its line is the only one sent, and the external routes are dropped. With ?routes=, every listed route streams, and the stream ends when all of them have answered or failed.
name Status Retry? Typical cause What to do
ValidationException 400 No A field is missing or malformed. Fix it. details[] names each field.
BadRequestException 400 No Build: the quote expired (Quote has expired. Please request a new quote.), from is missing or differs from the quote’s fromAddress, the quote is bound to another wallet, or recipient or refundTo differs from an earlier build. Submit: the hash format does not match the chain, the buildId is missing or stale, an anonymous quote is funded through a deposit address, or the existing order tracks another transaction. Quote again for an expired quote. Otherwise fix the request.
CannotFillException 400 No The route cannot build this deposit. details is hidden. Quote again, or choose another route.
UnexpectedFromAddressException 400 No The address does not fit the source chain’s family, on an external route. Use an address of the source chain’s family.
NotSupportedContractException 400 No A contract the route needs is not configured. Choose another route.
BuildDepositParsingException 400 No The route returned a plan the API could not validate. Quote again and build once more, then try another route.
NotSupportedDepositMethodException 400 No The depositMethod is not one the route offers. details holds depositMethod, fillerId and supportedMethods. Pick from supportedMethods, or leave depositMethod out.
BroadcastException 400 By errorCode Server-side broadcast failed. details is hidden; a failure may have been accepted. Follow the broadcast recovery rules above.
NotSupportedTokenException 404 No Build: the token is not supported on that chain. Use a token from GET /v1/tokens.
NotSupportedChainException 404 No Build: the chain is not supported. Submit: the API cannot broadcast on that chain. Use a chain from GET /v1/chains, or broadcast yourself and submit the hash.
NotSupportedAssetReverseContractException 404 No The native route has no deposit contract on that chain. Choose another route.
IntentNotFoundException 404 No The stored quote has no intent to build from. Quote again.
QuoteNotFoundException 404 No Unknown quoteId and routeId pair, a quote past its storage window (validBefore plus 60 seconds), or a quote already used by a successful submit. Quote again. After a submit that may have succeeded, look the order up with GET /v1/orders/{address} before doing anything else.
RATE_LIMITED (errorCode) 429 Yes Too many builds. See Limits and reliability. Back off and retry. There is no Retry-After.
InternalErrorException 500 Yes An unhandled server error. Retry with backoff, then contact Khalani with the x-request-id.
MaintenanceException 503 Yes Quotes and builds are paused. Retry after Retry-After.

A quote that no route can serve is not an error: POST /v1/quotes returns 200 with an empty routes[]. Unsupported tokens and chains only raise exceptions at the build.

Overlapping submits for the same transaction return the same orderId when both requests loaded the quote and filler registration succeeded. Hash casing does not change transaction identity. If the stored order tracks another transaction, expect 400 BadRequestException with details.errorCode: DEPOSIT_TX_HASH_CONFLICT and details.orderId. Look that order up before sending another deposit.

After a successful submit deletes the quote, a later retry can return 404 QuoteNotFoundException. Look the existing order up by address before taking further action.