Skip to main content

@acedatacloud/x402-client — Python

X402 payment protocol client for AceDataCloud APIs. Plug-in for the acedatacloud SDK.

Pay-per-request with USDC — no API key, no account, no session. When an AceDataCloud API returns 402 Payment Required, this package signs the payment envelope and returns it as an X-Payment header; the SDK retries transparently.

  • 🟦 Base — USDC (ERC-20) via EIP-3009 TransferWithAuthorization
  • 🟪 Solana — USDC (SPL) via signed TransferChecked
  • 🟨 SKALE — USDC (bridged) via EIP-3009

Install

pip install acedatacloud acedatacloud-x402

Quick start

Base or SKALE (EVM)

from acedatacloud import AceDataCloud
from acedatacloud_x402 import create_x402_payment_handler, EVMAccountSigner

client = AceDataCloud(
    base_url="https://x402.acedata.cloud",
    payment_handler=create_x402_payment_handler(
        network="base",                         # or "skale"
        evm_signer=EVMAccountSigner.from_private_key("0x..."),
    ),
)

res = client.openai.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Say hi in 3 words"}],
    max_tokens=10,
)
print(res.choices[0].message.content)

Solana

from acedatacloud import AceDataCloud
from acedatacloud_x402 import create_x402_payment_handler, SolanaKeypairSigner

client = AceDataCloud(
    base_url="https://x402.acedata.cloud",
    payment_handler=create_x402_payment_handler(
        network="solana",
        solana_signer=SolanaKeypairSigner.from_base58("..."),
    ),
)

task = client.images.generate(
    provider="nano-banana",
    prompt="a yellow banana on a white background",
)
result = task.wait()

The same handler works with AsyncAceDataCloud:

from acedatacloud import AsyncAceDataCloud

client = AsyncAceDataCloud(
    base_url="https://x402.acedata.cloud",
    payment_handler=create_x402_payment_handler(network="base", evm_signer=signer),
)

Low-level signing

If you need to produce an X-Payment envelope without going through the SDK:

from acedatacloud_x402 import sign_evm_payment, sign_solana_payment

envelope = sign_evm_payment(requirement, evm_signer)          # dict
envelope = sign_solana_payment(requirement, solana_signer)    # dict
# base64-encode json(envelope) → X-Payment header value

Metered billing — the upto scheme

For APIs whose true cost is only known after the response (chat completions, image edits, etc.) AceDataCloud advertises an extra upto accept entry alongside exact. upto uses Uniswap Permit2 to authorize a ceiling; the server settles the actual amount at /record time (which may be 0).

from acedatacloud_x402 import (
    EVMAccountSigner,
    create_x402_payment_handler,
)

client = AceDataCloud(
    base_url="https://x402.acedata.cloud",
    payment_handler=create_x402_payment_handler(
        network="base",
        evm_signer=EVMAccountSigner.from_private_key("0x..."),
        prefer_scheme="upto",   # opt-in; defaults to whatever the server lists first
    ),
)

A one-time on-chain ERC20.approve(Permit2, ∞) is required before the first upto payment. Use the bundled CLI:

pip install 'acedatacloud-x402[cli]'
X402_PRIVATE_KEY=0x... acedatacloud-x402 approve-permit2 --network base

or programmatically:

from acedatacloud_x402 import EVMAccountSigner, approve_permit2

approve_permit2(
    rpc_url="https://mainnet.base.org",
    signer=EVMAccountSigner.from_private_key("0x..."),
    token_address="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",  # USDC on Base
)

The helper is idempotent — re-running it after the allowance is already at or above the requested amount returns {"skipped": true} without sending a transaction.

Verified live on Base mainnet (2026-05-31)

End-to-end runs through https://facilitator.acedata.cloud against three metered chat endpoints, payer wallet 0x5d4f08D5c2bb60703284bc06671Eb680fA41B105:

API Model Credits charged USDC settled Tx
POST /v1/chat/completions claude-sonnet-4-5 0.001587893 0.000151 0xc1f90cc6…b093dd8
POST /openai/chat/completions gpt-5.5 0.001427432 0.000135 0xda8f0ff0…fcca57
POST /glm/chat/completions glm-4.7 0.002753977 0.000262 0xae9bba18…7c5dda

Each call advertised both exact and upto; the handler picked upto, the worker emitted an X-Usage-Exempt placeholder on the first /record, and the facilitator settled at the actual measured cost on the worker's later /record. Each settled amount matches the per-model JSONLogic cost rule in the gateway DB (within ±1 atomic for rounding).

Development

cd python
pip install -e ".[dev]"
pytest
ruff check .

License

MIT © AceDataCloud

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

acedatacloud_x402-2026.7.16.1.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

acedatacloud_x402-2026.7.16.1-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file acedatacloud_x402-2026.7.16.1.tar.gz.

File metadata

  • Download URL: acedatacloud_x402-2026.7.16.1.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for acedatacloud_x402-2026.7.16.1.tar.gz
Algorithm Hash digest
SHA256 5fcdbe449ddfa24b1d000c63bda21b52aad052e9f0ecdee24a5889a81b799e3c
MD5 cece854078f3be640c5728a0b028740a
BLAKE2b-256 c4306da40371ab1674aee93be3c27f0cb441144958ac43a437469907680705e3

See more details on using hashes here.

File details

Details for the file acedatacloud_x402-2026.7.16.1-py3-none-any.whl.

File metadata

File hashes

Hashes for acedatacloud_x402-2026.7.16.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4d8853e7ace771b368d26d453830e9bab2e92794b03fad3d622153ea1f4e7f2a
MD5 0ca9f85a76e2977a271a775386d13a88
BLAKE2b-256 e36c40301e3da094a3371c2a179f22496d69c3ddc8e25f7e4a8dee2e2f7d9e37

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page