Skip to main content

Error Format

All AgentWallex API errors follow a consistent JSON format:
{
  "code": "invalid_request",
  "type": "invalid_request_error",
  "message": "human readable error description"
}
FieldDescription
codeMachine-readable error code (e.g., policy_violation, insufficient_funds)
typeError category (see table below)
messageHuman-readable description of what went wrong

Error Types

TypeHTTP StatusDescription
invalid_request_error400The request body or parameters are invalid
authentication_error401Missing or invalid API key / token
authorization_error403Valid credentials but insufficient permissions
not_found_error404The requested resource does not exist
rate_limit_error429Too many requests — retry after the indicated delay
internal_error500Server-side error — contact support if persistent

Common Error Codes

CodeTypeDescription
policy_violationinvalid_request_errorTransaction blocked by policy engine
insufficient_fundsinvalid_request_errorWallet balance too low for the transaction
agent_frozeninvalid_request_errorAgent is frozen — unfreeze before transacting
invalid_chaininvalid_request_errorUnsupported or invalid chain ID
invalid_tokeninvalid_request_errorToken not supported on the specified chain
invalid_addressinvalid_request_errorMalformed recipient address
session_expiredinvalid_request_errorx402 session has expired or exceeded budget
rate_limit_exceededrate_limit_errorAPI rate limit reached
approval_timeoutinvalid_request_errorHuman approval was not granted within the timeout

SDK Error Handling

TypeScript

The TypeScript SDK provides typed error classes for specific error types:
import {
  AgentWallexError,
  PolicyViolationError,
} from "@agentwallex/sdk";

try {
  const tx = await aw.payments.send({
    agentId: "agent_abc123",
    to: "0xRecipientAddress",
    amount: "50.00",
    token: "USDC",
  });
} catch (error) {
  if (error instanceof PolicyViolationError) {
    console.log(`Policy violated: ${error.rule}`);
    console.log(`Details: ${error.message}`);
    // Handle: adjust amount, use different address, etc.
  } else if (error instanceof AgentWallexError) {
    console.log(`API error [${error.code}]: ${error.message}`);

    switch (error.code) {
      case "insufficient_funds":
        // Top up the wallet
        break;
      case "agent_frozen":
        // Unfreeze or use a different agent
        break;
      case "rate_limit_exceeded":
        // Wait and retry
        break;
      default:
        // Log and alert
        break;
    }
  } else {
    // Network error or unexpected exception
    console.error("Unexpected error:", error);
  }
}

Python

from agentwallex import AgentWallexError, PolicyViolationError

try:
    tx = await aw.payments.send(
        agent_id="agent_abc123",
        to="0xRecipientAddress",
        amount="50.00",
        token="USDC",
    )
except PolicyViolationError as e:
    print(f"Policy violated: {e.rule}")
    print(f"Details: {e.message}")
except AgentWallexError as e:
    print(f"API error [{e.code}]: {e.message}")
except Exception as e:
    print(f"Unexpected error: {e}")

Retry Strategy

Use exponential backoff for retries. Only retry on rate_limit_error and internal_error. Do not retry invalid_request_error or authentication_error — those require fixing the request.
async function withRetry<T>(
  fn: () => Promise<T>,
  maxRetries: number = 3
): Promise<T> {
  for (let attempt = 0; attempt <= maxRetries; attempt++) {
    try {
      return await fn();
    } catch (error) {
      if (
        error instanceof AgentWallexError &&
        (error.type === "rate_limit_error" || error.type === "internal_error") &&
        attempt < maxRetries
      ) {
        const delay = Math.pow(2, attempt) * 1000; // 1s, 2s, 4s
        await new Promise(resolve => setTimeout(resolve, delay));
        continue;
      }
      throw error;
    }
  }
  throw new Error("Max retries exceeded");
}

// Usage
const tx = await withRetry(() =>
  aw.payments.send({
    agentId: "agent_abc123",
    to: "0xRecipientAddress",
    amount: "50.00",
    token: "USDC",
  })
);

HTTP Status Code Reference

StatusMeaningAction
200SuccessProcess the response
201CreatedResource was created successfully
400Bad RequestFix the request parameters
401UnauthorizedCheck your API key
403ForbiddenCheck permissions / plan tier
404Not FoundVerify the resource ID exists
429Rate LimitedWait and retry with backoff
500Server ErrorRetry with backoff; contact support if persistent