OpenPermit Docs
SDK

Buyer SDK

Use wrapFetch to pay x402 and MPP resources from an agent workflow.

wrapFetch is the primary buyer integration. It sends the original request, detects supported payment challenges, authorizes the normalized payment intent against a mandate, executes payment, and retries with credential headers.

import { wrapFetch } from '@openpermit/sdk/buyer';
import { createOpenPermitClient } from '@openpermit/sdk/client';

const openpermit = createOpenPermitClient({
	baseUrl: 'https://api.openpermit.ai',
	apiKey: process.env.OPENPERMIT_API_KEY,
});

const paidFetch = wrapFetch(fetch, {
	client: openpermit,
	mandateId: 'mandate_...',
	idempotencyKey: (intent) => `agent-run-${intent.intentId}`,
	onPaymentExecuted: (execution, intent) => {
		console.log('paid', intent.intentId, execution.executionId);
	},
});

const response = await paidFetch('https://seller.example/paid/data');

Policy denials throw OpenPermitPolicyError. Malformed or unsupported payment challenges throw OpenPermitPaymentRequiredError.

Direct seller API calls work automatically only when the seller supports native x402/MPP challenges, OpenPermit seller middleware, or a compatible seller-direct OpenPermit flow.