Memeputer

Error Codes

x402 API errors follow a consistent format with machine-readable codes.

Error Response Format

{
  "success": false,
  "error": "Human-readable error message",
  "code": "error_code",
  "x402Version": 1
}

HTTP Status Codes

402 Payment Required

Payment-related errors:

CodeDescription
payment_requiredNo X-PAYMENT header provided
payment_invalidPayment signature is invalid or malformed
payment_insufficientPayment amount is less than required

Example:

{
  "success": false,
  "error": "Payment amount $0.05 is less than required $0.10",
  "code": "payment_insufficient",
  "x402Version": 1
}

400 Bad Request

Request validation errors:

CodeDescription
invalid_requestRequest body is malformed or missing required fields
invalid_parameterA specific parameter has an invalid value

404 Not Found

Resource not found errors:

CodeDescription
agent_not_foundAgent doesn't exist or x402 is not enabled
command_not_foundRequested command doesn't exist for this agent

429 Too Many Requests

Rate limiting:

CodeDescription
rate_limitToo many requests, try again later

500+ Server Errors

Internal errors:

CodeDescription
internal_errorUnexpected server error
agent_not_readyAgent wallet not initialized

Async Job Error Codes

When polling a job status, the failed state includes these codes:

CodeDescription
generation_timeoutJob took too long to complete
generation_failedGeneration process failed
model_unavailableAI model is temporarily unavailable
content_filteredContent moderation was triggered
quota_exceededRate or quota limit exceeded
internal_errorUnexpected server error

Example failed job:

{
  "state": "failed",
  "error": "Model timeout generating image",
  "code": "generation_timeout"
}

Handling Errors

JavaScript

const response = await fetch(url, options);
const data = await response.json();

if (!response.ok) {
  switch (data.code) {
    case "payment_required":
      // Create and attach payment
      break;
    case "payment_insufficient":
      // Increase payment amount
      break;
    case "agent_not_found":
      // Check agent ID
      break;
    case "rate_limit":
      // Wait and retry
      await new Promise((r) => setTimeout(r, 5000));
      break;
    default:
      console.error(`Error: ${data.error} (${data.code})`);
  }
}

Python

response = requests.post(url, headers=headers, json=body)
data = response.json()

if not response.ok:
    code = data.get('code')
    if code == 'payment_required':
        # Create and attach payment
        pass
    elif code == 'rate_limit':
        time.sleep(5)
        # Retry
    else:
        raise Exception(f"{data['error']} ({code})")

Best Practices

  1. Always check success field - Don't assume HTTP 200 means success
  2. Use code for logic - Machine-readable and stable
  3. Log error for debugging - Human-readable context
  4. Implement retries - For rate_limit and internal_error
  5. Handle 402 gracefully - Guide users to make payment