OpenPermit Docs
Guides

Add OpenPermit to a Buyer Agent

Use wrapFetch so an agent can call paid HTTP resources under an active mandate.

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 method, chain, and spend amount.

Pass your runtime fetch to wrapFetch and use the returned function for paid resource requests.

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();