PerpsError with a numeric code, the originating tool (DEX), and a human-readable message.
PerpsSDKError which carries the numeric error code:
Error Types
For more specific handling, the SDK exports specialized error classes and utilities to inspect the error chain:| Class | When thrown | Useful fields |
|---|---|---|
PerpsSDKError | Top-level wrapper for all SDK errors | code, message, cause |
HTTPError | API returned a non-2xx response | status, url, responseBody |
AgentError | Agent not found or not authorized for DEX | code, message |
ServerError | Network failure or timeout | code, message |
ValidationError | Client-side parameter validation failed | message |
Error Code Ranges
Error codes use the 2000+ range to avoid collision with the main LI.FI API (which uses 1000+):| Range | Category | Description |
|---|---|---|
| 2000-2009 | Base errors | Server errors, validation, timeout |
| 2010-2019 | Auth errors | Signature and authorization failures |
| 2020-2039 | Trading errors | Order execution and market errors |
| 2040-2049 | Nonce errors | Nonce validation and expiry |
| 2050-2059 | Payload errors | Payload integrity failures |
| 2060-2069 | Routing errors | Invalid API routes |
Error Code Reference
Base Errors (2000-2009)
| Code | Name | HTTP | Description |
|---|---|---|---|
DefaultError | 500 | Unexpected server error | |
ServerError | 500 | Internal server error | |
ValidationError | 400 | Request validation failed | |
TimeoutError | 408 | Request timeout | |
ThirdPartyError | 424 | External service failure |
Authentication Errors (2010-2019)
| Code | Name | HTTP | Description |
|---|---|---|---|
SignatureInvalid | 401 | Signature verification failed | |
AgentUnauthorized | 403 | Agent wallet not approved |
Trading Errors (2020-2039)
| Code | Name | HTTP | Description |
|---|---|---|---|
ExchangeRejected | 422 | DEX rejected the operation | |
InsufficientMargin | 422 | Not enough margin for the order | |
InsufficientBalance | 422 | Not enough balance | |
MarketNotFound | 404 | Unknown market/symbol | |
OrderNotFound | 404 | Order doesn’t exist | |
PositionNotFound | 404 | Position doesn’t exist |
Nonce Errors (2040-2049)
| Code | Name | HTTP | Description |
|---|---|---|---|
InvalidNonce | 400 | Nonce validation failed | |
NonceAlreadyUsed | 409 | Nonce already consumed | |
NonceExpired | 410 | Nonce TTL exceeded |
Payload Errors (2050-2059)
| Code | Name | HTTP | Description |
|---|---|---|---|
PayloadMismatch | 400 | Signed payload doesn’t match stored |
Routing Errors (2060-2069)
| Code | Name | HTTP | Description |
|---|---|---|---|
RouteNotFound | 404 | Invalid API route / endpoint does not exist |
SDK Error Code Constants
The SDK exportsPerpsErrorCode for type-safe error handling:
Troubleshooting
ExchangeRejected (2020)
The DEX backend rejected the request. Check:- Order parameters are valid (size within limits, price within bounds)
- The market is active and not in maintenance
- Request body matches the expected schema
InsufficientMargin (2021)
Not enough margin for the requested order. Check:- Account has sufficient USDC balance
- Existing positions don’t consume too much margin
- Reduce leverage or order size
InsufficientBalance (2022)
Account lacks funds for the operation. Check:- Deposit sufficient funds to your DEX account
- Check balances with
getAccount()
SignatureInvalid (2010)
The signature could not be verified. Check:- The correct wallet/agent signed the
typedData - The
typedDatawas not modified after creation - The nonce has not expired (re-call
createOrderorcreateAuthorizationto get fresh data)
AgentUnauthorized (2011)
The agent wallet is not approved on the DEX. Check:- The authorization flow completed successfully (both
createAuthorizationandsubmitAuthorization) - The agent address matches what was authorized
- The authorization has not been revoked
MarketNotFound (2023)
The symbol doesn’t exist on the specified DEX. Check:- Use
getMarkets()to list valid symbols - Symbol is case-sensitive (use
BTC, notbtc) - The market hasn’t been delisted
OrderNotFound (2024)
The order ID doesn’t exist. Check:- Use the correct
orderId(from the submit response) - The order may have already been fully filled or cancelled
- Verify the
dexparameter matches where the order was placed
PositionNotFound (2025)
No position exists for the specified symbol. Check:- Verify you have an open position for this symbol
- Use
getAccount()to list current positions
InvalidNonce (2040)
The nonce in the request failed validation. Check:- The
typedDatawas not modified after creation - Re-call the create endpoint to get fresh payloads
NonceAlreadyUsed (2041)
The nonce has already been consumed by a previous request. This typically happens when:- Submitting the same signed payload twice
- Re-submitting after a successful operation
NonceExpired (2042)
The nonce has exceeded its time-to-live. Payloads expire after a short period for security. Check:- Sign and submit payloads promptly after creation
- Re-call the create endpoint to get fresh payloads
PayloadMismatch (2050)
The signed payload doesn’t match what was stored server-side. This can happen if:- The
typedDatawas modified before signing - A different payload was substituted
typedData returned from the create endpoint without modification.
ThirdPartyError (2004)
An external service (typically the DEX) returned an error. Check:- DEX may be experiencing issues
- Retry after a short delay
- Check DEX status pages for outages
TimeoutError (2003)
The request exceeded the timeout limit. Check:- Network connectivity
- DEX may be experiencing high latency
- Retry the operation