Docs

Start with one governed paid request.

This page is the shortest path to a useful first integration: install the SDK, create one client, choose the right request path, and understand how 402flow handles observing paid traffic, policy denials, rail selection, and receipt finality.

Start here

  • Install `@402flow/sdk` and create one client per agent identity.
  • Use `fetchPaid(...)` for known requests or prepare/revise/execute when the agent needs to reason about the request first.
  • Keep policy decisions, policy review events, receipt finality, and rail selection in the control plane instead of the app runtime.
QuickstartView repo
import {
  AgentHarness,
  AgentPayClient,
  defaultHarnessInstructions,
  defaultHarnessToolSpecs,
} from '@402flow/sdk';

const client = new AgentPayClient({
  controlPlaneBaseUrl: 'https://api.402flow.ai',
  organization: 'acme-labs',
  agent: 'research-worker',
  auth: {
    type: 'bootstrapKey',
    bootstrapKey: process.env.X402FLOW_BOOTSTRAP_KEY ?? '',
  },
});

const harness = new AgentHarness({ client });

console.log(defaultHarnessInstructions);
console.log(defaultHarnessToolSpecs.map((spec) => spec.name));
// [ 'prepare_paid_request', 'execute_prepared_request', 'get_execution_result' ]

Quickstart

What to do first.

You do not need a large implementation plan to evaluate 402flow. One request path is enough to prove the model.

Install the SDK

Start from `npm install @402flow/sdk` and keep the integration surface small.

Create one client per agent

Use `AgentPayClient` with your control-plane base URL, organization, and agent identity.

Choose the paid-request path

Use `fetchPaid(...)` when the request is already known, or prepare/execute when the agent needs to reason about the request first.

Run one real request

Prove one end-to-end paid request against the demo, then compare it with a policy denial or observed-only discovery case before you broaden the integration.

Choose a path

Use the smallest request path that fits the host.

Most integration choices collapse to one question: do you already know the request, or does the caller need to inspect and revise it first?

fetchPaid(...)

Fast path

Use this when the host already knows the merchant URL, method, headers, and body and just needs the shortest governed execution path.

prepare + execute

Direct inspect + execute

Use this when the application or orchestrator wants direct control over the prepared request. You inspect parameter hints, validation issues, and the next action, then decide when to execute.

AgentHarness

Model-host tools

Use the harness when the caller is a model host. AgentHarness exposes the same prepare, execute, and result lifecycle through a stable three-tool contract with default instructions.

Platform model

Why the control plane matters.

402flow does more than pay a challenge. It keeps merchant discovery, policy decisions, and rail selection explicit and reviewable.

Discover merchants before setup

Under Default allow and monitor, 402flow can track spend against merchants that are not yet configured in Setup. Those merchants appear in Reports as observed-only until the org decides to promote them.

Deny now, refine policy later

When a managed request does not satisfy policy, 402flow denies it before execution and creates a policy review event. Operators adjust policy for future traffic instead of approving one request at a time.

Choose rails deterministically

When a merchant advertises multiple compatible rails, 402flow follows the enabled wallet order to pick the highest-precedence compatible path. The rule is explicit, deterministic, and visible in receipts and reports.

Policy model

Policies can be as broad or granular as the workflow needs.

The same policy model can express an org-wide cap, a merchant-specific budget, an agent-specific limit, or a shared budget across selected merchants or agents. It can also enforce a single-request ceiling or a day, week, or month window before execution proceeds.

Scope policy at the org, merchant, or agent level

A policy can apply org-wide or to merchant- and agent-scoped traffic. Non-org scopes can target selected sets of merchants or agents, or all merchants or agents, and can apply either as a shared cap or a per-member cap.

Use per-request or over-time limits

Limits can deny a single request based on its current amount, or evaluate cumulative spend over day, week, or month windows before execution continues.

Keep the amount model explicit

Policies are amount-based and asset-aware, so org caps, merchant budgets, and agent spend limits all use one structured model instead of ad hoc rules in app code.

Example stack

One concrete way to layer policies.

  • Org monthly cap: the organization cannot spend more than 500 USDC this month.
  • Agent daily cap: each selected research agent gets its own 25 USDC daily budget.
  • Merchant per-request cap: each selected data vendor is capped at 1 USDC per request.

A single request can match all three. 402flow evaluates the current request amount together with any applicable time-window usage before execution continues.

Shared vs per-member

The same scope can behave like a pool or separate budgets.

  • Shared merchant weekly cap: three selected vendors share one 100 USDC weekly budget.
  • Per-member merchant weekly cap: those same vendors each get their own 100 USDC weekly budget.
  • Shared agent daily cap: a selected set of agents all draws from one daily budget.

Shared policies pool usage across every matching merchant or agent. Per-member policies keep separate headroom for each matching merchant or agent inside the same selected set.

Runtime notes

The constraints that matter early.

These are the details worth knowing before you wire the SDK into a real paid-request path.

Node 20+ is the current supported runtime.

Replayable request bodies matter early: use strings or URLSearchParams for paid prepare and execute flows.

Bootstrap-key auth is the recommended default for most SDK integrations.

Organizations can start with either "Deny by default" or "Default allow and monitor," depending on whether they want strict blocking or observed-only merchant discovery first.

Receipt finality can be provisional first; the chain observer later promotes confirmed receipts once the onchain finality rule is satisfied.

Next step

Read the SDK, then prove one real flow.

The next useful move is not more reading. It is one governed paid request through the SDK, the demo-merchant, and the lifecycle you expect to operate in production.