a13n
AI 에이전트를 만들고 클라우드에서 실행합니다
메이커가 쓴 소개는 위의 한 줄이 전부입니다. 더 자세한 내용은 저장소 README에서 읽을 수 있습니다. 저장소 README ↗
README 전체를 불러오는 중입니다.
README 전문 보기 ↗A Cloudflare Worker that exposes APIs on a pay-per-use basis using the x402 protocol on Stacks.
| Environment | Base URL | Network | Docs |
|---|---|---|---|
| Production | https://x402.aibtc.com | mainnet | /docs |
| Staging | https://x402.aibtc.dev | testnet | /docs |
/inference/* - LLM chat completions (OpenRouter, Cloudflare AI)/stacks/* - Blockchain utilities (address, decode, profile, verify)/hashing/* - Clarity-compatible hashing functions/storage/* - Stateful operations (KV, paste, DB, sync, queue, memory)Full endpoint documentation available at /docs.
All paid endpoints use the x402 v2 protocol with base64-encoded JSON headers.
Supported tokens: STX, sBTC, USDCx (via X-PAYMENT-TOKEN-TYPE header)
Flow:
payment-required headerpayment-signature headerpayment-response headerHeaders:
payment-signature (request): Base64-encoded payment payloadpayment-required (402 response): Base64-encoded payment requirementspayment-response (success): Base64-encoded settlement resultX-PAYMENT-TOKEN-TYPE (optional): Token selector (STX, sBTC, USDCx)npm install # Install dependencies
npm run dev # Local development
npm run check # Type check
Note: Do not run
npm run deploydirectly. Commit and push for automatic deployment.
E2E payment tests against live endpoints using the x402 protocol.
# Copy and configure environment
cp .env.example .env
# Set your testnet mnemonic (NEVER use mainnet funds!)
export X402_CLIENT_PK="your twelve word testnet mnemonic"
# Optional: target staging instead of localhost
export X402_WORKER_URL=https://x402.aibtc.dev
npm test # Quick mode - stateless endpoints, STX only
npm run test:full # Full mode - includes lifecycle tests
npm run test:verbose # With debug output
npm run test:kv # Just KV lifecycle test
# Filter by category or name
bun run tests/_run_all_tests.ts --category=hashing
bun run tests/_run_all_tests.ts --filter=sha256 --all-tokens
For the immediate-pay-per-call stabilization path, run a focused staging or production check against a cheap paid endpoint:
export X402_WORKER_URL=https://x402.aibtc.dev
bun run tests/_run_all_tests.ts --filter=sha256 --token=STX --retries=2 --verbose
On any retryable 402 during this check, confirm the body stays on canonical caller-facing semantics:
status never returns submittedpaymentId is present before retrying the same paymentterminalReason is the normalized terminal signal when presentcheckStatusUrl is treated as additive when present| Mode | Description |
|---|---|
quick | Stateless endpoints only (hashing, stacks, inference) |
full | Stateless + lifecycle tests for stateful endpoints |
# Cron job (runs hourly, logs only on failure)
0 * * * * /path/to/x402-api/scripts/run-tests-cron.sh
MIT