x402 top-ups

Moth DocsReference

POSThttps://api.runmoth.ai/v1/credits/x402?amount_usd=25

Adds credit with one signed USDG transfer over HTTP, in the x402 v2 format. Moth sends the transfer on Robinhood Chain and pays the gas.

curl -X POST https://api.runmoth.ai/v1/credits/x402?amount_usd=25 \
  -H "Authorization: Bearer $MOTH_API_KEY"
Response
PAYMENT-RESPONSE  base64 of { success: true, transaction, network: "eip155:4663", payer }
{
  "id": "x402_3f9c2a7d1e8b4c6a5f0e2d1c",
  "status": "sent",
  "amount_usd": "25.000000",
  "tx_hash": "0x9f…",
  "error": null,
  "created_at": "2026-12-01T18:20:04.000Z"
}

A top-up takes two calls to the same address. The first, without a signature, answers 402 with one offer. The second sends the signed offer back in the PAYMENT-SIGNATURE header, and Moth checks it, sends the transfer and answers with the top-up. Use one of your own API keys or a wallet session. A free session can't top up. Top up with x402 has a full example, and Let an agent pay for its own inference has the whole loop for an agent.

Query or headerWhat it is
amount_usdRequired, in the query. The credit to add in dollars, from 1 to 1000, with up to six decimals.
PAYMENT-SIGNATUREOn the second call. Base64 of { x402Version: 2, accepted, payload: { signature, authorization } }, where accepted is the offer you took and authorization is the signed EIP-3009 TransferWithAuthorization.

The offer

Without PAYMENT-SIGNATURE, or when a signature doesn't check out, the answer is 402. Its body is the offer, and the PAYMENT-REQUIRED header carries the same JSON in base64. amount is in USDG's six-decimal units, payTo is your account's deposit address, and extra names USDG's EIP-712 domain. After a failed check, error says why.

json
{
  "x402Version": 2,
  "resource": {
    "url": "https://api.runmoth.ai/v1/credits/x402?amount_usd=25",
    "description": "Moth credit top-up, credited to the account behind this key or session",
    "mimeType": "application/json"
  },
  "accepts": [
    {
      "scheme": "exact",
      "network": "eip155:4663",
      "amount": "25000000",
      "asset": "0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168",
      "payTo": "0x5aE1…c09B",
      "maxTimeoutSeconds": 600,
      "extra": {
        "name": "Global Dollar",
        "version": "1",
        "assetTransferMethod": "eip3009"
      }
    }
  ]
}
  • Only the exact scheme on eip155:4663 is accepted, for the asked amount, to your own deposit address.
  • validBefore may be at most 10 minutes ahead, and a signature with less than 20 seconds left is refused.
  • Before sending, Moth checks that the authorization is unused, that the paying wallet holds the USDG and that the transfer would go through.

What comes back

Moth waits up to about 20 seconds for the transfer to be sent. If it is, the answer is 200 with the transaction in the body and in the PAYMENT-RESPONSE header. If not yet, the answer is 202 with the same body and tx_hash still null. The credit itself comes from the deposit, as for any transfer to your deposit address, so the balance shows it a few seconds after the transfer is mined.

StatusMeaning
queuedChecked and waiting to be sent
sentSent on chain, with its tx_hash, and waiting for the receipt
settledThe USDG reached your deposit address
failedThe transfer would not go through, and error says why. Nothing moved
expiredThe signature ran out before it was sent. Nothing moved

Read a top-up

GET /credits/x402/{id} returns one of your top-ups in the same shape as above. A top-up that isn't yours, or doesn't exist, answers 404 with not_found_error.

Whether x402 is open

GET /credits/x402/status says whether top-ups are open now, and the limits. While open is false, message says why and the POST answers 503.

json
{
  "open": true,
  "message": null,
  "network": "eip155:4663",
  "asset": "0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168",
  "min_usd": "1.000000",
  "max_usd": "1000.000000",
  "max_timeout_seconds": 600
}

Both reads take one of your API keys or a wallet session, and answer 401 without one. Deposits lists the deposit each top-up becomes.

Errors

400invalid_request_erroramount_usd is missing or badly formed, or outside $1 to $1,000
401authentication_errorNo wallet session or API key of the account was sent, and a free session can't top up
402payment_requiredNo PAYMENT-SIGNATURE was sent, or it didn't check out, was already used, or the transfer would fail; the body is a fresh offer with error saying why
429rate_limit_errorMore than 10 tries this hour, or three top-ups are still on their way
503overloaded_errorx402 is paused for a moment, or deposits aren't open, so send USDG to your deposit address instead
On this page