Skip to main content
Types and utilities for configuring x402 payment gating on agent and tool endpoints.
import type { Accepts, AcceptsX402, AcceptsFree } from "aixyz/accepts";
import { HTTPFacilitatorClient, facilitator } from "aixyz/accepts";

Types

Accepts

Union type for payment configuration:
type Accepts = AcceptsX402 | AcceptsFree;

AcceptsX402

Requires x402 exact payment:
type AcceptsX402 = {
  scheme: "exact";
  price: string; // USD string, e.g. "$0.005"
  network?: string; // CAIP-2 chain ID, overrides config
  payTo?: string; // EVM address, overrides config
};
FieldTypeRequiredDescription
schemestringYesMust be "exact"
pricestringYesUSD price string (e.g. "$0.005")
networkstringNoCAIP-2 chain ID, overrides x402.network from config
payTostringNoEVM address to receive payment, overrides x402.payTo config

AcceptsFree

No payment required:
type AcceptsFree = {
  scheme: "free";
};

Exports

HTTPFacilitatorClient

Client for communicating with an x402 facilitator service. Re-exported from @x402/core/server.
import { HTTPFacilitatorClient } from "aixyz/accepts";

const client = new HTTPFacilitatorClient({
  url: "https://x402.use-agently.com/facilitator",
});

facilitator

The default facilitator client used by AixyzServer. Points to the Agently-hosted x402 facilitator.
import { facilitator } from "aixyz/accepts";

AcceptsScheme

Zod schema for validating Accepts objects at runtime:
import { AcceptsScheme } from "aixyz/accepts";

AcceptsScheme.parse({ scheme: "exact", price: "$0.005" });

Usage

Agents and tools declare an accepts export to control x402 payment gating. Endpoints without accepts are not registered.
// app/agent.ts
import type { Accepts } from "aixyz/accepts";

export const accepts: Accepts = {
  scheme: "exact",
  price: "$0.005",
};
// app/tools/lookup.ts
import type { Accepts } from "aixyz/accepts";

export const accepts: Accepts = {
  scheme: "free",
};

Custom facilitator

Create app/accepts.ts to override the default facilitator:
// app/accepts.ts
import { HTTPFacilitatorClient } from "aixyz/accepts";

export const facilitator = new HTTPFacilitatorClient({
  url: process.env.X402_FACILITATOR_URL ?? "https://x402.use-agently.com/facilitator",
});