Look up a single tweet. The SDK intercepts 402 responses, pays via Tempo, and retries automatically.
import { Mppx, tempo } from "mppx/client";import { privateKeyToAccount } from "viem/accounts";// Configure the MPP client — this patches global fetch// to automatically handle 402 Payment Required challengesMppx.create({ methods: [ tempo({ account: privateKeyToAccount(process.env.TEMPO_PRIVATE_KEY as `0x${string}`), }), ],});// Now any fetch to an MPP-enabled endpoint auto-paysconst response = await fetch( "https://xquik.com/api/v1/x/tweets/1893456789012345678");const data = await response.json();console.log(data.tweet.text);
Mppx.create() patches the global fetch function. When a request returns 402 with a WWW-Authenticate: Payment header, the SDK pays the requested amount ($0.00015) and retransmits the request with an Authorization: Payment credential. The response includes a Payment-Receipt header confirming settlement.
Search tweets with per-result pricing. You pay $0.00015 per tweet returned.
// Global fetch is already patched by Mppx.create() aboveconst response = await fetch( "https://xquik.com/api/v1/x/tweets/search?q=TypeScript&limit=20");const data = await response.json();console.log(`Found ${data.tweets.length} tweets`);// Cost: $0.00015 × number of tweets returned
Session payments deposit funds upfront and deduct per result. The SDK manages the deposit and voucher exchange automatically. Your maximum cost = price × limit parameter (e.g., searching with limit=20 at 0.00015/tweetcostsatmost0.003).
The request parameter is a base64url-encoded JSON object containing the amount, currency, and recipient address.Step 3: Pay and retryAfter completing the Tempo payment, retry the request with the payment credential:
The Authorization: Payment value is a base64url-encoded JSON object containing the original challenge and your payment proof.Step 4: Receive the response + receipt