Migration Guide
Migrate from raw x402 to Sentinel.
Migrating to Sentinel is a one-line change. Your existing x402 flow stays intact.
Before: Raw x402
import { x402Client, wrapFetchWithPayment } from "@x402/fetch";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
const client = new x402Client();
registerExactEvmScheme(client, { signer });
const fetchWithPayment = wrapFetchWithPayment(fetch, client);
const response = await fetchWithPayment("https://api.example.com/paid");After: With Sentinel
import { x402Client, wrapFetchWithPayment } from "@x402/fetch";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { wrapWithSentinel, standardPolicy } from "@valeo/x402";
const client = new x402Client();
registerExactEvmScheme(client, { signer });
const fetchWithPayment = wrapFetchWithPayment(fetch, client);
const secureFetch = wrapWithSentinel(fetchWithPayment, {
agentId: "agent-001",
budget: standardPolicy(),
});
const response = await secureFetch("https://api.example.com/paid");Migration Steps
- Install
@valeo/x402 - Wrap your x402 fetch with
wrapWithSentinel - Replace all usages of the old fetch with the wrapped one
- Add try/catch for
SentinelBudgetErrorwhere you want graceful handling - Optional: Add storage, hooks, metadata
Zero Breaking Changes
- Same
fetchsignature:(input, init?) => Promise<Response> - Same response format
- Same 402 flow — Sentinel only intercepts; it doesn't change the protocol
Gradual Rollout
Migrate one agent at a time. Use different fetch instances:
const fetchWithPayment = wrapFetchWithPayment(fetch, client);
const legacyFetch = fetchWithPayment;
const newFetch = wrapWithSentinel(fetchWithPayment, {
agentId: "agent-new",
budget: standardPolicy(),
});
const fetchToUse = useSentinel ? newFetch : legacyFetch;Start with unlimitedPolicy() to get audit logging without budget enforcement. Add limits once you've observed typical spend.