Repository navigation
docs(x402): the settle token, one settlement per payment, metered payments, x402-fetch 0.3.0, x402 0.8.1 and CLI 0.4.1 - #33
Merged
Conversation
…ments, x402-fetch 0.2.3 and CLI 0.4.1 - quickstart, migration recipe: @parallel-protocol/x402 0.8.0 or later; the facilitator has required the settle token since 1 October 2026, and older versions' settlements are refused with SETTLE_TOKEN_REQUIRED. What happens behind the scenes: the token from verify to settle, a failed settlement's 402 with its reason, the one retry of a settle whose outcome is unknown. - concepts: what verify checks (BAC-375), the token, one settlement per payment and alreadySettled (BAC-376), and exact and metered (upto) payments: USDp only, a window of 3,600 s at most, the two minutes the SDK keeps for the settlement and its retry, AMOUNT_MISMATCH. - agent quickstart: x402-fetch 0.2.3 on CLI ^0.4.0 and the faster signing of 0.4.1; the dailyBudget, timeoutMs and allowInsecure options and the chain default; UNKNOWN_CHAIN, BUDGET_EXCEEDED, UNSUPPORTED_SCHEME and ENGINE_NOT_FOUND; metered invoices; what the agent gets when a settlement fails; one payment at a time, no automatic retry. - CLI: MIT; pay prepare's --scheme upto and --valid-for, and the signing domain read from DOMAIN_SEPARATOR() since 0.4.1. - FAQ, x402 overview, risks: the settle retry, the token, one settlement per payment, verify's checks, MIT for the CLI; the "120-second verify window" is gone, since a settle after it is rebuilt from the verified payment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…not prevent, which settlement failures ask for a check with the merchant, and a Next.js tab that compiles - agent-quickstart, the safety model: a wrapper's queue keeps dailyBudget exact but does not set aside what it signed; two payments signed together can each fit a balance that covers one, and the chain refuses the second settlement (INSUFFICIENT_BALANCE), possibly after the merchant has served. QA reproduced it with 0.015 USDp and two 0.01 payments. - agent-quickstart, when the settlement fails: FACILITATOR_INVALID_RESPONSE, AMOUNT_MISMATCH and SETTLE_TOKEN_REQUIRED/INVALID ask for a check with the merchant, as the message @parallel-protocol/x402 0.8.0 sends the agent for each says. So does AUTHORIZATION_USED: the facilitator answers it as a 409, consumed or cancelled on-chain and not settled by it, and if someone else settled the authorization, the merchant was paid. The SDK settles once the handler has answered, before it sends the response. - quickstart, Next.js tab: payTo as const, and the handler returns NextResponse.json as withPayment's handler type requires; it compiles in strict TypeScript against x402 0.8.0 and Next 15.5.27 (it did not before this PR either). - concepts: the metered handler gets maxTimeoutSeconds minus 120 s, and 30 s at least. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… a repeated settle returns the confirmation or the refusal - agent-quickstart, when the settlement fails: SUBMISSION_FAILED joins the reasons that ask for a check with the merchant before paying again. The facilitator also returns it when a settlement is interrupted after a transaction went out, an outcome it cannot know yet, so paying again could pay twice. - concepts: a settle repeated after a lost answer returns what was recorded, the confirmation, marked alreadySettled, or the refusal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ake the agent pay twice
When the settlement fails, in the agent quickstart:
- TX_REVERTED joins the reasons that ask for a new payment. Like
INSUFFICIENT_BALANCE, PAYMENT_EXPIRED and RELAYER_UNAVAILABLE, the payment
was not taken and the facilitator will not settle it.
- Four reasons join the ones that ask for a check with the merchant first:
- UNKNOWN: the SDK could not read why the settlement failed;
- PAYMENT_NOT_VERIFIED: a repeated settle also gets it after a first
attempt whose transaction may still be mined;
- PARALLELIZER_PAUSED and SERVICE_UNAVAILABLE: refused before anything was
sent, the payment can still be settled until it expires.
- Any reason the list does not name asks for a check with the merchant too,
and the error codes page gives the detail.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
|
Thanks, this is accurate for x402-fetch 0.2.3 and x402 0.8.0. Two releases went out that change a few lines:
#32 now carries the settlement routes table (A to L and U, |
…FetchError, and x402 0.8.1 calls the facilitator over https only
agent-quickstart
- x402-fetch 0.3.0 is the version a fresh install gets, still with the
CLI 0.4.1. A project on 0.2 moves by installing it, since a ^0.2
range does not reach 0.3.
- A paid request the merchant answers with 402 now rejects with
X402FetchError instead of returning the response:
- PAYMENT_REFUSED when the merchant asks for payment again (a new
section);
- SETTLEMENT_FAILED when it could not settle.
Both carry reason and retryAfter. The code sample, the refusals table
and "When the settlement fails" say where the agent reads them on
0.3.0, and on earlier versions.
- The safety model: the engine now gets only the settings it needs,
not the caller's whole environment.
quickstart and migrate-from-coinbase-x402
- The facilitator URL must use https, plain http being accepted only on
localhost, 127.0.0.1 and [::1]. A redirect is never followed: it
fails the call with FACILITATOR_UNAVAILABLE. Both since x402 0.8.1.
No page mentions FacilitatorClient.pay(), which 0.8.1 deprecates.
Sources: the changelogs, READMEs and type definitions of x402-fetch
0.3.0 and x402 0.8.1 on npm (sdk-merchant #62 and #63, published by
#64).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 4, 2026
decodePaymentResponse throws INVALID_INVOICE when the receipt header cannot be decoded, after the request was paid. In the quickstart it ran inside the try whose comment says every other code comes before any payment, so an agent following it could pay twice. It now runs after the try, with a comment saying the request is already paid. Also say that CLI 0.4.1 still loads a .env file from the working directory or a parent, and ~/.parallel/config.toml: the environment list does not cover files on disk. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Merchant quickstart and Coinbase migration recipe: use
@parallel-protocol/x402 0.8.1 or later. 0.8.0 is the first to send the
settle token; 0.8.1 adds the https-only facilitator URL and the
no-redirect rule these pages already describe.
- Agent quickstart:
- CLI 0.4.1 falls back to a .env found from its install directory,
which is the project's, when none is found from the working directory;
- the receipt comment says any payment was sent by now, rather than
that the request is paid;
- the two codes that come after the payment are those from payFetch.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…uses - The safety model no longer says the CLI reads ~/.parallel/config.toml. The CLI 0.4.1 reads it only for defaults that x402-fetch already passes (--chain and --wallet), so a payment does not read it. - The INVALID_INVOICE row names the malformed invoice fields, as in the x402-fetch 0.3.0 README: payTo or asset not an address, an amount that is not a positive integer, or decimals that contradict the token catalog or fall outside 0 to 36. A 402 without a readable invoice is not one of them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The x402, SDK, x402-fetch, CLI and facilitator content of the docs catches up with Parallel's releases of 28 September to 2 October:
@parallel-protocol/x4020.8.0 and 0.8.1;@parallel-protocol/x402-fetch0.2.3 and 0.3.0;@parallel-protocol/cli0.4.1;This PR leaves out:
api-reference,error-codes,schemas,verify-vs-settle);Sources:
@parallel-protocol/x402,@parallel-protocol/x402-fetchand@parallel-protocol/cli;--help;Pages
agents/x402/quickstart@parallel-protocol/x4020.8.1 or later (0.8.1 since8774ba3, see the last round). Since 1 October 2026 the facilitator settles only when the settle presents the token it issued at verify. Earlier versions do not send it, and their settlements are refused withSETTLE_TOKEN_REQUIRED.402 PAYMENT_SETTLEMENT_FAILEDwith itsreason;payToisas const, and the handler returnsNextResponse.json, aswithPayment's handler type requires and as the package README writes it.tsc(strict) against x402 0.8.0 and Next 15.5.27.agents/x402/conceptsalreadySettled, or the refusal;SETTLE_TOKEN_REQUIREDandSETTLE_TOKEN_INVALID.uptopayment signs a cap, valid 3,600 s at most, in USDp only;maxTimeoutSecondsminus 120 s, and 30 s at least;AMOUNT_MISMATCH.agents/x402/agent-quickstartdailyBudget,timeoutMsandallowInsecure, and thechaindefault;UNKNOWN_CHAIN,BUDGET_EXCEEDED,UNSUPPORTED_SCHEMEandENGINE_NOT_FOUND, andengineCode.INSUFFICIENT_BALANCE,PAYMENT_EXPIREDandTX_REVERTED, and later forRELAYER_UNAVAILABLE: the payment was not taken, and the facilitator recorded the failure, so it will not settle it.SETTLE_TIMEOUT,FACILITATOR_UNAVAILABLE,FACILITATOR_INVALID_RESPONSE,SETTLE_IN_PROGRESS,RECEIPT_UNAVAILABLE,AMOUNT_MISMATCH,SETTLE_TOKEN_REQUIREDandSETTLE_TOKEN_INVALID: for each, x402 0.8.0 sends the agent exactly that advice in itsmessage(published package).SUBMISSION_FAILED: the facilitator also returns it when a settlement is interrupted after a transaction went out, so the payment may still settle.UNKNOWN: the SDK's reason for an answer that carries no code it can read (x402 0.8.0 README). Itsmessagegives no advice.PAYMENT_NOT_VERIFIED: the facilitator also answers a repeated settle with it after a first attempt whose transaction it could not confirm, and that transaction may still be mined.PARALLELIZER_PAUSEDandSERVICE_UNAVAILABLE: refused before anything is sent, so the same settle can still go through until the authorization expires.AUTHORIZATION_USED: the facilitator answers it with a 409. The authorization is "no longer usable on-chain (consumed or cancelled)" and was "not settled by this facilitator". If someone else settled it, the merchant was paid.dailyBudgetexact, and it never retries;INSUFFICIENT_BALANCE, possibly after the merchant has served.agents/x402/indexandagents/cli/indexlicensefield, and theLICENSEfile shipped in 0.4.1).agents/cli/commandspay prepare --scheme upto, and--valid-for(3,600 at most).DOMAIN_SEPARATOR()instead ofversion(), which is faster on Base.ROUTE_UNAVAILABLEfor a token whose domain matches no known version.--helpand the published package. Each statement was run offline.agents/faqagents/recipes/migrate-from-coinbase-x402@parallel-protocol/x4020.8.1 or later: 0.8.0 for the settle token, 0.8.1 for the facilitator URL checks.security/risksSETTLE_TIMEOUT;AMOUNT_MISMATCH.PAYMENT_EXPIRED) or a payment never verified (PAYMENT_NOT_VERIFIED) is refused.Not documented as done
These are still open at Parallel, and this PR states only what ships:
uptoin USDC;Checks
All runs were offline, under
sandbox-execwith localhost only, at 60e0b2b.pnpm typecheck: clean.pnpm test: 348/348, in 32 files.pnpm build: passes. Offline, the share-card font from brand.parallel.best does not load, and pages keep the staticog-image.png.linkinator dist/public --recurse --clean-urls --check-fragments, with external links skipped: all 414 internal links OK./agents/x402/concepts#exact-and-metered-payments,#metered-invoicesand#when-the-settlement-fails./products/parallel-v2: old GitBook paths.pnpm generate:sidebarwas not run. No page was added.Round: x402-fetch 0.3.0 and x402 0.8.1 (
33e04cf)Both were published on 2 October.
agents/x402/agent-quickstart^0.2range does not reach 0.3.402now rejects withX402FetchErrorinstead of returning the response:PAYMENT_REFUSED, in a new section, "When the merchant refuses the payment";SETTLEMENT_FAILED: "When the settlement fails" now says where an agent on 0.3.0 reads the reason and theRetry-After(err.reason,err.retryAfter), and where one on an earlier version does (the body and the header).agents/x402/quickstartandagents/recipes/migrate-from-coinbase-x402localhost,127.0.0.1and[::1].FACILITATOR_UNAVAILABLE.Also:
FacilitatorClient.pay(), which 0.8.1 deprecates.api-referenceanderror-codespages are not changed here.Checks at
33e04cf:pnpm typecheckis clean,pnpm testpasses 348/348 in 32 files, andpnpm buildpasses.--check-fragments, external links skipped: all 414 internal links OK.#when-the-merchant-refuses-the-payment./products/parallel-v2.pnpm generate:sidebarwas not run.Round: the receipt is read after the payment (
21dcdfc)agents/x402/agent-quickstartdecodePaymentResponsethrowsINVALID_INVOICEwhen thepayment-responseheader cannot be decoded (x402-fetch 0.3.0,dist/index.js). That happens after the request was paid, but the call sat inside thetrywhose comment says every code other thanPAYMENT_REFUSEDandSETTLEMENT_FAILEDis raised before any payment, so an agent retrying on it would pay twice. Thetrynow wrapspayFetchalone and rethrows, and the receipt is decoded after it, with a comment saying the request is already paid. In 0.3.0, the onlyX402FetchErrorcodespayFetchraises after the paid request are those two, so the comment holds.INVALID_INVOICErow saysdecodePaymentResponsealso throws it, after the payment..envfile from the agent's working directory or any parent directory (the engine runs in that directory). Source: the published CLI 0.4.1 (findEnvFile) and x402-fetch 0.3.0 (execFilewith nocwd).Checks at
21dcdfc:pnpm typecheckis clean,pnpm testpasses 348/348 in 32 files, andpnpm buildpasses, offline.strict,NodeNext, TypeScript 5.9.3) against the published x402-fetch 0.3.0, with the DOM lib, and with Node's types alone underskipLibCheck(without the DOM lib, a dependency's own type definitions need it)./products/parallel-v2.pnpm generate:sidebarwas not run.Round: 0.8.1 minimum, and three precisions (
8774ba3)agents/x402/quickstartandagents/recipes/migrate-from-coinbase-x402@parallel-protocol/x4020.8.1 on both pages. 0.8.0 is the first version to send the settle token; 0.8.1 adds the https-only facilitator URL and the no-redirect rule, which both pages already describe. Each page now says so in a sentence.agents/x402/agent-quickstart.envfallback. When no.envis found walking up from the working directory, the CLI 0.4.1 walks up from its own install directory, inside the project'snode_modules, and so finds the project's.env. The safety model now says so. Source: the published CLI 0.4.1 (loadEnvcallsfindEnvFilea second time, from the directory of its own script).402, or when the merchant does not settle. The conclusion stays:INVALID_INVOICEfromdecodePaymentResponseis no reason to pay again.payFetch, sincedecodePaymentResponsecan also throw after it.Checks at
8774ba3:pnpm typecheckis clean,pnpm testpasses 348/348 in 32 files, andpnpm buildpasses, offline.strict,NodeNext, TypeScript 5.9.3) against the published x402-fetch 0.3.0./products/parallel-v2.pnpm generate:sidebarwas not run.Round:
config.toml, and the causes ofINVALID_INVOICE(12f8573)agents/x402/agent-quickstart~/.parallel/config.toml. The CLI 0.4.1 reads it only for defaults: the chain when--chainis missing, and the keystore when--wallethas no value. x402-fetch 0.3.0 always passes--chainand--wallet env, so a payment does not read it. The sentence on the.envfile stays.INVALID_INVOICErow now reads: "An invoice field is malformed: apayToorassetthat is not an address, an amount that is not a positive integer, or decimals that contradict the token catalog or fall outside 0 to 36." The sentence ondecodePaymentResponsefollows unchanged. Source: the x402-fetch 0.3.0 README andresolvePaymentin itsdist/index.js. A402without a readable invoice is not one of these:payFetchreturns it as it is.Checks at
12f8573:main(1168335), somainwas not merged in.pnpm typecheckis clean,pnpm testpasses 348/348 in 32 files, andpnpm buildpasses, offline.pnpm generate:sidebarwas not run.🤖 Generated with Claude Code