x402sms
Guides

Python client

Full activation flow with the x402 Python SDK.

pip install "x402[httpx]" eth-account

Complete example

import asyncio
import os
import time

from eth_account import Account
from x402 import x402Client
from x402.http.clients import x402HttpxClient
from x402.mechanisms.evm import EthAccountSigner
from x402.mechanisms.evm.upto.register import register_upto_evm_client

BASE = "https://api.sms-x402.xyz"

account = Account.from_key(os.environ["PRIVATE_KEY"])
client = x402Client()
register_upto_evm_client(client, EthAccountSigner(account))

async def main() -> None:
    async with x402HttpxClient(client, base_url=BASE) as http:
        # 1. order — 402 handled automatically
        order = await http.post("/v1/numbers", json={"service": "tg", "country": 16})
        data = order.json()
        activation_id, token = data["id"], data["accessToken"]
        print("number:", data["number"])

        # 2. use the number in the target service, then poll
        while True:
            await asyncio.sleep(7)
            res = await http.get(
                f"/v1/numbers/{activation_id}",
                headers={"Authorization": f"Bearer {token}"},
            )
            body = res.json()
            if body["status"] == "completed":
                print("SMS code:", body["code"])
                break
            if body["status"] != "waiting_code":
                raise RuntimeError(f"activation ended: {body['status']}")

asyncio.run(main())

Cancel (costs $0)

await http.post(
    f"/v1/numbers/{activation_id}/cancel",
    headers={"Authorization": f"Bearer {token}"},
)

Notes

  • An upto-capable client is required — payments signed with the exact scheme are rejected.
  • Status endpoints need only the accessToken, not payment.

On this page