ai-paywall-agent-sdk-sui
v1.0.0
Published
Drop-in SUI paywall client for AI agents. Intercepts HTTP 402 challenges, builds and submits pay_and_unlock PTBs automatically, retries with payment headers — budget-capped and replay-safe.
Maintainers
Readme
ai-paywall-agent-sdk-sui
Drop-in fetch() replacement for AI agents. Automatically detects, pays, and retries
SUI HTTP 402 paywalls via pay_and_unlock Programmable Transaction Blocks.
Install
npm install ai-paywall-agent-sdk-sui @mysten/suiQuick Start
import { createSuiAgentClient, fromKeypairFile } from "ai-paywall-agent-sdk-sui";
const client = createSuiAgentClient({
network: "testnet",
signer: fromKeypairFile(), // ~/.sui/sui_config/sui.keystore
maxPerRequestMist: 10_000_000, // hard cap: 0.01 SUI/request
maxTotalMist: 1_000_000_000, // session budget: 1 SUI
});
// Drop-in fetch — 402s paid automatically
const res = await client.fetch("https://publisher.com/articles/ai-trends");
const data = await res.json();
console.log("spent:", client.spend(), "MIST");
console.log("address:", client.address());How It Works
On a 402:
- Parses
challenge.objectId,challenge.priceMist,challenge.move.target - Checks budget caps (throws
BudgetExceededErrorif exceeded) - Builds PTB:
splitCoins(gas, [priceMist])→pay_and_unlock(challenge, coin, clock) - Retries with
X-SUI-PAYMENT-TX+X-SUI-CHALLENGE-IDheaders - Returns the unlocked response
Vault (split) mode is detected automatically from the 402 body — no extra config.
Error Handling
import { BudgetExceededError, PaymentRefusedError } from "ai-paywall-agent-sdk-sui";
try {
const res = await client.fetch(url);
} catch (err) {
if (err instanceof BudgetExceededError) { /* cap hit */ }
if (err instanceof PaymentRefusedError) { /* TX failed on-chain */ }
}Full Documentation
See docs/AGENT.md or the Tollgate website.
License
MIT
