acedatacloud is responsible for API calls, while acedatacloud-x402 is responsible for producing the PAYMENT-SIGNATURE request header.
Source code and package URLs:
- SDK repository: https://github.com/AceDataCloud/SDK
- X402 Client repository: https://github.com/AceDataCloud/X402Client
- PyPI SDK: https://pypi.org/project/acedatacloud/
- PyPI X402 Client: https://pypi.org/project/acedatacloud-x402/
Install Dependencies
upto, you also need to run the Permit2 approve CLI once. This CLI depends on web3:
- Both
acedatacloudandacedatacloud-x402can be installed and imported from PyPI. pip install 'acedatacloud-x402[cli]'includes theapprove-permit2CLI, which is used for prerequisite authorization forupto.
Base Example
The example below does not require an API Token. The wallet private key is only used for local signing and will not be sent to Ace Data Cloud.dict, so the example uses res["choices"][0]["message"]["content"]. Do not directly assume that it necessarily has a .choices attribute.
Solana Example
Solana uses a base58-encoded secret key:TransferChecked transaction, then puts the transaction signature into the PAYMENT-SIGNATURE envelope.
The Solana paid retry has returned HTTP 200 and ADC_SOLANA_E2E_OK on the production API. This public RPC query encountered rate limiting and did not reliably confirm the on-chain signature; use your own Solana RPC to query the transaction when reconciliation is needed.
Async Client
The same payment handler can be used withAsyncAceDataCloud:
Using upto Post-Payment Metering
The actual cost of APIs such as chat completions and model invocations may only be known after the response has completed. In this case, the API may return both exact and upto. To prioritize using upto:
upto program execution result:
content ADC_BASE_UPTO_OKindicates that the request actually reached the model API.settled value 3 atomic USDCindicates thatuptosettles based on actual usage rather than charging the full limit.settlement txcan be opened in BaseScan. Save the tx hash, payer, completion id, and request summary for reconciliation.
upto uses Permit2 to authorize a limit, and the actual settlement amount cannot exceed this limit. Before first use, you need to perform a one-time approve(Permit2, amount) for USDC on the target chain.
CLI method:
{"skipped": true} and does not send another on-chain transaction.
Low-Level Signing
If you do not use the SDK, you can also directly call the low-level signing function:create_x402_payment_handler.
