PayAI docs

Getting Started

Use From npm

Install the published packages:

npm install @payai-sh/core @payai-sh/x402

Run Locally

Clone the repository and install dependencies:

npm install

Run checks:

npm run check

Run the demo:

npm run demo

The demo simulates:

  1. An agent requests a paid API.
  2. The API returns 402 Payment Required.
  3. PayAI parses the quote and checks the grant.
  4. A mock x402 payer adds payment headers.
  5. The API returns the paid resource.
  6. PayAI records a receipt.

Packages

@payai-sh/core

Core policy primitives:

@payai-sh/x402

Fetch wrapper for x402-like paid resources:

Minimal Example

import { createPayAIFetch } from "@payai-sh/x402";

const payaiFetch = createPayAIFetch({
  grant,
  payer: async (request) => {
    request.paymentHeaders.set("X-Payment", "mock-payment");
    return request.fetch(request.paymentHeaders);
  }
});

const response = await payaiFetch("https://data.example.com/report", {
  purpose: "research"
});