Skip to main content
This tutorial describes the complete process of Ace Data Cloud X402 with a minimal API request. The goal is not to write complex code first, but to understand: why the first request returns 402, what is in accepts, and how PAYMENT-SIGNATURE turns the same API request into a paid request.

Preparation

You need to prepare: When calling the Ace Data Cloud API with X402, an API Token is not required. The SDK’s first request does not include Authorization, and the Gateway will return 402 Payment Required along with payment requirements; the SDK will automatically retry after signing.

Install SDK

Source code and package addresses: TypeScript:
Python:
If you want to use Solana, you also need to install the corresponding dependencies:
The Python version of the Solana signer dependency is already included in acedatacloud-x402. Installation and import check output for a clean temporary environment:
Result explanation:
  • The npm packages and PyPI packages are real published packages, not placeholder names in the documentation.
  • acedatacloud-x402[cli] will install the CLI, and the approve-permit2 subcommand can be used for Permit2 authorization in the upto scenario.

The First Request Will Return 402

You can first use curl to see what an unpaid request returns. The following example will not incur a charge because it does not carry PAYMENT-SIGNATURE:
The response body will contain the accepts array, with a common structure as follows:
The same challenge content will also be placed in base64 format in the PAYMENT-REQUIRED response header, allowing the client to read the payment requirements without parsing the body. The output summary of the program for unpaid requests to the production API is as follows:
Result explanation:
  • The first request did not carry Authorization or PAYMENT-SIGNATURE, so it returned HTTP 402 and did not incur a charge.
  • accepts is the only trusted signature basis for this request, containing optional networks, schemes, maximum amounts, payment addresses, and asset addresses.
  • network is the CAIP-2 identifier, and the client must match the network according to the CAIP-2 string.
  • The maximum amount for this minimal chat request of gpt-4o-mini is 95215 atomic USDC, which is 0.095215 USDC.
  • Each request should read the 402 response of the current request and not hard-code the example amount into the business code.
Field meanings:

Complete Payment Retry with SDK

Below is the minimal TypeScript example. It specifies network: 'skale', and the handler will select the SKALE payment requirement from this 402 response; the actual amount and payment address will still be based on accepts:
The result of running the program with the TypeScript SDK on the same link:
Result explanation:
  • content ADC_TS_SDK_X402_OK is a fixed string returned by the model according to the prompt, indicating that the payment retry successfully entered the model API.
  • payer is the local signed wallet address, and the private key was not sent to Ace Data Cloud.
  • The SDK completed the 402 parsing, PAYMENT-SIGNATURE signing, and original request retry; the business code is still written in the usual SDK call manner.
Four steps occurred behind this code:
  1. The SDK sends a normal API request without Authorization.
  2. The Gateway returns 402 Payment Required and accepts.
  3. createX402PaymentHandler selects the payment requirement for network = 'skale' and signs out PAYMENT-SIGNATURE.
  4. The SDK retries with the same request body, and the Gateway calls the Facilitator for verification and settlement before allowing access to the target API.

View Facilitator Support Capabilities

The X402 API does not rely on a resource directory. The client directly calls known APIs and uses the 402 Payment Required and accepts returned in real-time as the only basis for price and signature. The capability declaration of the Facilitator is located at:
It only describes /supported, /verify, /settle, and the currently enabled payment networks, without listing API resources. The production Facilitator address for Ace Data Cloud is:
You can check which networks and schemes it supports:
The returned kinds will list the networks and schemes supported by the Facilitator. Actual calls should still be based on the accepts returned by the API. Facilitator /supported output:
Result explanation:
  • /supported indicates that the Facilitator has the verification and settlement capabilities for these networks and schemes.
  • Base, SKALE, and Solana all support exact; upto is currently only available on Base.
  • Whether a specific API allows a certain network is still subject to the 402 accepts of that API.