#!/usr/bin/env python3 """Free sample + unpaid HTTP 402. No wallet required. A paid retry should use the published x402 Python SDK (PyPI package x402, extras httpx and evm) with a signer that you already hold. This file does not construct a payment and does not read a private key, so it is safe to run as-is. """ from __future__ import annotations import json import sys import urllib.error import urllib.request BASE = "https://api.aestheticdata.io" def get(path: str) -> tuple[int, dict[str, str], bytes]: req = urllib.request.Request(BASE + path, method="GET") try: with urllib.request.urlopen(req, timeout=30) as res: return res.status, {k.lower(): v for k, v in res.headers.items()}, res.read() except urllib.error.HTTPError as exc: return exc.code, {k.lower(): v for k, v in exc.headers.items()}, exc.read() def main() -> int: status, _headers, body = get("/sample") print(f"GET /sample -> HTTP {status}") data = json.loads(body.decode()) datasets = [d.get("dataset") for d in data.get("datasets", [])] print("datasets:", datasets) print("This path is free. No payment header is required.") print() status, headers, body = get("/x402/brands") print(f"GET /x402/brands -> HTTP {status}") print("content-type:", headers.get("content-type")) print("PAYMENT-REQUIRED present:", "payment-required" in headers) if status != 402: print("Unexpected status; expected 402 on an unpaid paid route.", file=sys.stderr) return 1 print("v2 clients decode PAYMENT-REQUIRED (Base64) and retry with PAYMENT-SIGNATURE.") print("v1 clients read the JSON body and retry with X-PAYMENT. Do not send both.") print("Atomic amount 1000 = 0.001 USDC.") print("Paid retry: use package x402 with extras [httpx, evm], keep keys in the environment,") print("and cap spend at the route price (0.001-0.005 USDC).") return 0 if __name__ == "__main__": raise SystemExit(main())