OpenPermit Docs
Guides

Add OpenPermit to a Buyer Agent

Use smart-account continuations or wrapFetch so agents can call paid HTTP resources under an active mandate.

For generic agents that can open links but cannot submit arbitrary POST bodies, use the browser-first continuation flow. The seller returns a setup link, the buyer approves the mandate in OpenPermit, and OpenPermit opens the seller-hosted continuation URL so the store can finish checkout server-side.

Use the continuation API directly only from SDK-capable buyer apps or seller servers:

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

const openpermit = createOpenPermitClient({
	baseUrl: process.env.OPENPERMIT_API_URL ?? 'http://localhost:9999',
	apiKey: process.env.OPENPERMIT_API_KEY,
});

const readiness = await openpermit.checkAgentCommerceReadiness({
	mandateId: process.env.OPENPERMIT_MANDATE_ID!,
	storefrontUrl: 'https://storefront.example',
	sellerId: 'seller_...',
	resourceId: 'storefront:checkout',
	paymentChallenge: 'x402',
	paymentMode: 'metamaskErc7715',
	chain: 'eip155:84532',
	asset: 'USDC',
	payTo: '0xSellerPayTo...',
	tokenAddress: '0xUsdcToken...',
	tokenDecimals: 6,
	tokenName: 'USDC',
	tokenVersion: '2',
	metadata: {
		merchantContinuationUrl: 'https://storefront.example/agent-payments/continue/session_123?checkoutSession=checkout_session_123',
	},
});

if (readiness.status === 'ready') {
	const continuation = await openpermit.createAgentCommerceContinuation(readiness.scope);
	console.log(continuation.agentInstructions); // Link-first seller continuation instructions.
}

Use wrapFetch only when your agent runtime can run the SDK directly and provide the required payment credential. Generic browser-only agents should follow seller setup and continuation links.

Configure createOpenPermitClient with an API key that can authorize payments for the active organization.

Use an active mandate whose policy permits the seller, resource, payment challenge type, chain, and spend amount.

Pass your runtime fetch to wrapFetch and use the returned function for paid resource requests when your agent can run the SDK directly.

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

const openpermit = createOpenPermitClient({
	baseUrl: process.env.OPENPERMIT_API_URL ?? 'http://localhost:9999',
	apiKey: process.env.OPENPERMIT_API_KEY,
});

export const paidFetch = wrapFetch(fetch, {
	client: openpermit,
	mandateId: process.env.OPENPERMIT_MANDATE_ID!,
	metadata: {
		agentRunId: 'run_...',
	},
});

Use normal Fetch semantics after wrapping:

const response = await paidFetch('https://seller.example/paid/search?q=weather');
const data = await response.json();