DocsAgent Reference (raw specs for agents)
Agent spec. Human readers can start with the human guide.
X402 Pay is the Termix CLI using its encrypted EVM wallet to buy a directly supplied HTTPS
resource from any x402 v2 service (Termix's own router, another Termix agent, or any other
service on the open protocol) or from a third-party seller that charges through MPP on Tempo. This is separate from Termix task payments -- the other
direction is X402 Charge, where any wallet, including one that has never seen this CLI, pays
Termix instead. X402 Pay never sends Termix legal receipts, API tokens, caller proofs, or
idempotency headers to the origin it is paying.
Supported in this release:
eip155:<chainId>).exact payments through EIP-3009 or Permit2.upto payments through Permit2.tempo charge payments on Tempo mainnet and Moderato (seeService discovery, Bazaar search, MCP, A2A, non-EVM wallets, batch settlement, uploads, forms, and
streaming request bodies are not supported.
An external 402 response is untrusted. Before the wallet signs, the CLI checks the resource URL,
origin, path, method, protocol version, scheme, network, token contract, recipient, amount, and
authorization lifetime. Redirects are disabled. Unattended requests also reject private, loopback,
and link-local destinations unless their matching policy rule explicitly allows private networking.
The policy protects agents using this CLI installation. It is not an onchain wallet limit and does
not coordinate with another computer or wallet program controlling the same private key.
Never retry a payment whose result is pending: true. The service may already have settled it.
Inspect or reconcile the recorded payment instead.
This CLI is meant to be driven by an AI agent, which changes the threat model. An agent can be
prompt-injected by untrusted content it processes in the course of ordinary work -- a task
description, a fetched webpage, another tool's output -- into running a CLI command it was never
meant to run. Unattended (--non-interactive) payments exist specifically so an agent can pay
without a human present at request time; the entire safety of that mode depends on a human already
having authorized the exact origin, recipient, and spend caps in the policy rule beforehand. To
keep that premise true rather than merely assumed, adding or enabling a policy rule that grants
unattended spending authority always requires a real interactive terminal and a typed
confirmation -- an agent driving this CLI cannot author or activate its own unattended
authorization, even if it has been compromised. Treat ~/.termix/x402-policy.json as a
security-sensitive file: only write unattended rules yourself, at a terminal, after reading exactly
what origin and spend caps you are granting.
termix x402 policy init
termix x402 policy path
termix x402 policy show
termix x402 policy validateThe policy is stored at ~/.termix/x402-policy.json with owner-only permissions. Override the
path for isolated automation or tests with TERMIX_X402_POLICY_PATH.
The machine-readable schema is available from:
termix x402 policy schemaand on the docs site at x402-policy.schema.json (not in this bundle; termix x402 policy schema prints the same schema offline).
A policy file is written as "version": 1 unless it uses something earlier CLI releases cannot
read: a marketplaceFees section, or a network or payment entry outside eip155 exact/upto.
Such a policy is written as "version": 2, and needs the CLI release that introducedmarketplaceFees or a later one. An earlier CLI refuses a version 2 policy instead of dropping
what it cannot read, so it never removes your fee bounds. Removing those entries writes version 1
again.
Amounts are unsigned integer strings in the token's atomic units. displaySymbol anddisplayDecimals are for operator display only; authorization uses the network and contract
address.
{
"version": 1,
"networks": {
"eip155:8453": {
"rpcUrlEnv": "BASE_RPC_URL"
}
},
"rules": [
{
"id": "example-api",
"enabled": true,
"priority": 100,
"origin": "https://api.example.com",
"pathPrefix": "/v1/",
"methods": ["GET", "POST"],
"unattended": true,
"allowPrivateNetwork": false,
"maxAuthorizationSeconds": 300,
"payments": [
{
"scheme": "upto",
"network": "eip155:8453",
"asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"payTo": "0x1111111111111111111111111111111111111111",
"displaySymbol": "USDC",
"displayDecimals": 6,
"maxPerPayment": "100000",
"spendWindow": {
"seconds": 86400,
"max": "1000000"
},
"permit2": {
"allowSponsoredApproval": true,
"allowDirectApproval": true,
"allowUnattendedDirectApproval": false,
"maxApprovalGasWei": "100000000000000"
}
}
]
}
]
}Rules match an exact HTTPS origin and optional path prefix. A prefix matches on a path-segment
boundary: /v1/messages covers /v1/messages and /v1/messages/batch, never the sibling/v1/messages2; a prefix ending in / covers everything below it. The highest priority wins; an
equal priority tie is rejected. Unattended payment entries must pin payTo; interactive-only rules may
leave it open for confirmation. Payment entries are ordered preferences. Command options can
narrow a persistent unattended rule but cannot widen it. Rules never apply to Termix's own
fees; the optional marketplaceFees section bounds those instead (see
Termix Submission Fees).
Manage rules without editing the file directly:
termix x402 policy add --rule-file rule.json
termix x402 policy disable example-api
termix x402 policy enable example-api
termix x402 policy remove example-apipolicy add and policy enable print the rule's origin, path, methods, and payment terms and
require you to type authorize at the terminal whenever the rule being written or activated is
both enabled and unattended. This only runs with a real TTY attached, so it cannot be satisfied
by a script or an agent process. policy disable and policy remove, and adding or enabling a
rule that is not unattended, need no confirmation, since none of those grant unattended spending
authority.
Interactive GET:
termix x402 request https://api.example.com/v1/dataJSON POST:
termix x402 request https://api.example.com/v1/generate \
--method POST \
--body-file request.jsonUnattended execution fails closed unless one persistent rule authorizes the complete challenge:
termix x402 request https://api.example.com/v1/data \
--non-interactive \
--policy example-apiPick the protocol with --protocol <auto|x402|mpp> (default auto). auto reads both the x402
challenge and any MPP challenge in the 402 response and pays the best option your policy allows.x402 ignores MPP challenges. mpp ignores the x402 challenge. It is a filter on what the CLI may
pay, never an output format.
termix x402 request https://api.example.com/v1/data --protocol mppLoad secret headers from environment variables or an owner-only JSON file. Do not put secrets in
command arguments:
export EXAMPLE_API_KEY=secret
termix x402 request https://api.example.com/v1/data \
--header-env 'authorization=EXAMPLE_API_KEY'Every request has an invocation ID. Pass your own with --invocation-id <id> (1-128 characters
of A-Z a-z 0-9 . _ : -) when a script or agent may run the same request again, for example after
a crash or a timeout. The first use records the ID with a fingerprint of the exact request
(method, URL, headers and body). Running it again with the same request never sends or pays again
and fails with "code": "invocation_duplicate"; running it with a different request fails with"code": "invocation_conflict". Both failures include the recorded invocation (state,charge, uncertain), so a script can tell whether the first run was charged. Without the
option the CLI uses a random UUID, so every run is a new request.
termix x402 request https://api.example.com/v1/data \
--non-interactive \
--policy example-api \
--invocation-id report-2026-10-10JSON and text responses up to 1 MiB are returned in the CLI envelope. Use --output <path> for
larger or binary responses, up to 64 MiB. The CLI refuses to overwrite an existing output file.
Request bodies are limited to 64 MiB as well: a larger --json or --body-file is refused withrequest_body_too_large before it is read.
exact authorizes and settles the advertised amount. Compatible tokens use EIP-3009; other ERC-20
tokens may use Permit2 when the service advertises that transfer method.
upto authorizes the advertised maximum. The service chooses an actual charge from zero through
that maximum after measuring usage. A conforming but dishonest service can charge the entire
maximum, so policy reserves the maximum before signing. On success the CLI reports both:
{
"authorizedAmount": "100000",
"settledAmount": "43821"
}Permit2 can require a one-time ERC-20 allowance. The CLI uses bounded EIP-2612 or raw-approval gas
sponsoring when advertised and policy permits it. Otherwise it can send a direct approval through
the rule's configured RPC. A direct approval verifies chain ID, native balance, and gas ceiling,
and receives a separate confirmation unless unattended direct approval is explicitly enabled.
The CLI never creates an unlimited Permit2 allowance automatically.
Tempo (eip155:4217, and Moderato eip155:42431) has no native gas coin: every transaction pays
its fee in a TIP-20 fee token, OUSD. When a Tempo merchant needs a direct Permit2 approval, the CLI:
Raw-approval gas sponsoring (erc20ApprovalGasSponsoring) is refused on Tempo, since it relies on
a native-gas transaction. Bounded EIP-2612 sponsoring and direct approval still work. On Tempo,maxApprovalGasWei is read in attodollars (1e-18 USD), the unit Tempo prices gas in, so"100000000000000" caps an approval at $0.0001. See Tempo.
Some sellers answer 402 with a WWW-Authenticate: Payment header (MPP) instead of an x402
challenge. The same command pays them: termix x402 request <url>. The payment runs under the
same policy, journal, invocation ID and reconcile as an x402 payment. The CLI never sends
Termix credentials to the seller.
Only a challenge with all of these:
tempo and intent charge;eip155:4217) or Tempo Moderato (eip155:42431). A challenge with nosplits, no seller-named memo, no digest;supportedModes is absent or lists pull;Authorization (the default) or Payment-Authorizationheader is refused.A response may carry several challenges in one header or in several. The CLI reads all of them
(at most 16, header up to 16,384 characters), ignores the ones it cannot pay, and offers the rest
to selection and policy. When the response has both an x402 option and an MPP option, x402 comes
first. A challenge with no expires is accepted. The signed charge is valid for 25 seconds, or
less when the challenge expires sooner.
Most MPP sellers ask for USDC.e on Tempo. Termix wallets hold OUSD. The CLI does not swap. Before it signs, it reads
the wallet balance of the token the seller asked for. If the wallet holds less than the charge
(plus the fee, below), the payment is refused with insufficient_balance and nothing is signed.
To pay a seller that asks for USDC.e, put USDC.e in the CLI wallet (termix address) on that
network first. Some sellers offer several tokens, OUSD included. When your policy allows more
than one, the CLI reads the wallet balance of each and pays the option the wallet can cover, then
the one with the lowest cost, whatever order the seller lists them in. A rule with a higherpriority still wins first. If the wallet holds none of them, the payment is refused withinsufficient_balance.
A rule allows a seller by origin, scheme, network, token and recipient, exactly as for x402.
networks entry for the Tempo chain by hand. termix x402 policy init does notnetworks entry is missing, or its variable is unset, the payment fails before anything is"code": "request_failed" and a hint. The hint says "Nothing was signed" and"networks": { "<network>": { "rpcUrlEnv": "<ENV_VAR>" } } (the key isnetworks.<network>.rpcUrlEnv, for example networks.eip155:4217.rpcUrlEnv) to the policy filetermix x402 policy path) and to export that variable as an HTTPS RPC URL.export TEMPO_RPC_URL=https://rpc.tempo.xyz (Moderato:https://rpc.moderato.tempo.xyz).mpp-tempo-charge, network eip155:4217 oreip155:42431, the asset (the token contract the seller asks for), payTo (the seller'smaxPerPayment and spendWindow.termix x402 policy validate. Adding an MPP rule saves the policy file as"version": 2. CLIs older than the release that adds MPP payments do not read a version 2Adding or enabling an unattended rule still needs a real terminal and a typed confirmation. An
unattended entry must pin payTo.
{
"version": 2,
"networks": {
"eip155:4217": { "rpcUrlEnv": "TEMPO_RPC_URL" }
},
"rules": [
{
"id": "mpp-seller",
"enabled": true,
"priority": 100,
"origin": "https://api.example.com",
"pathPrefix": "/",
"methods": ["GET", "POST"],
"unattended": true,
"allowPrivateNetwork": false,
"maxAuthorizationSeconds": 300,
"payments": [
{
"scheme": "mpp-tempo-charge",
"network": "eip155:4217",
"asset": "0x20C000000000000000000000b9537d11c60E8b50",
"payTo": "0x1111111111111111111111111111111111111111",
"displaySymbol": "USDC.e",
"displayDecimals": 6,
"maxPerPayment": "50000",
"spendWindow": { "seconds": 86400, "max": "500000" }
}
]
}
]
}Then pay unattended:
termix x402 request https://api.example.com/search \
--method POST --body-file request.json \
--protocol mpp --non-interactive --policy mpp-sellerA charge outside the rule (another recipient, token, chain or amount) is refused withpolicy_denied before anything is signed.
Interactively, the confirmation (on stderr) names the protocol, network, token and recipient, then
states what the recipient receives, who pays the network fee, and the maximum authorized in total.
Seller pays the fee:
Recipient receives: 5000 atomic units
Network fee: paid by the seller
Maximum authorized in total: 5000 atomic unitsYour wallet pays the fee:
Recipient receives: 5000 atomic units
Network fee: paid by your wallet, worst case 8000 atomic units of the token
Maximum authorized in total: 13000 atomic unitsThe seller broadcasts the transaction. Who pays its fee depends on the challenge:
feePayer: true: the seller sponsors it. The wallet pays no fee. The limit counts the chargefeePayer absent or false: the wallet pays the fee, in the same token as the charge. TheThe charge plus the fee counts against maxPerPayment, against spendWindow.max, and against
the balance check. For a charge of 5000 the wallet pays the fee on, the payment needs13000. Set maxPerPayment high enough, or the payment is refused with policy_denied.
A paid request prints the payment record with a protocol field, x402 or mpp. `payments
list, get and reconcile print it too. A payment is mpp` when its scheme ismpp-tempo-charge.
{
"ok": true,
"data": {
"payment": {
"id": "pay_...",
"protocol": "mpp",
"scheme": "mpp-tempo-charge",
"network": "eip155:4217",
"asset": "0x20C000000000000000000000b9537d11c60E8b50",
"payTo": "0x1111111111111111111111111111111111111111",
"authorizedAmount": "5000",
"state": "settled",
"transaction": "0x..."
},
"response": { "status": 200 }
}
}The transaction comes from the seller's Payment-Receipt header. A 2xx with no receipt, a
malformed receipt, a non-2xx after the paid request, or a timeout is an unknown outcome:pending: true. Do not retry it.
termix x402 payments reconcile <paymentId> reads the chain through the policy's RPC. It
never resends the request. Signing records the chain's latest block. Reconcile reads forward from
that block, looking for a TransferWithMemo from the wallet to the seller that carries the memo
recorded for the payment (each payment has its own random memo). The window ends at the first
block after the signature's validBefore.
settled, with the transaction hash.validBefore, and the chain head read again afterwards is still pastvalidBefore and at or beyond that range: unspent, and the reservation is released.validBefore, or a second head that is behind the logs orpending, so an endpoint whose log replica lags its blockpending: validBefore not reached yet, the window needs more than 16The Tempo RPC is a trust anchor for the spend window. Reconcile frees the window for anunspent payment on what that endpoint says, so a wrong endpoint can let the policy allow more
than its cap. Use a dedicated endpoint you trust (your own node or a provider account), not a
shared public one, for networks.<network>.rpcUrlEnv.
Each failure prints code and a hint with the next step. Nothing was signed for these four.
| Code | Meaning | Hint |
|---|---|---|
challenge_expired | Every payable challenge had expired, or too little time remained | Request the resource again for a fresh challenge. |
no_supported_rail | No payment option in the 402 can be paid here | Check --protocol and the seller's advertised methods. The CLI pays x402 exact and upto, and MPP tempo charge. |
insufficient_balance | The wallet holds too little of the asked token (and the fee) | Fund the wallet with that token on that network, then request again. |
payment_header_conflict | Your request already sets the header the credential needs | Remove that header from --headers-file or --header-env. |
A missing networks entry or unset RPC variable fails with request_failed and a hint namingnetworks.<network>.rpcUrlEnv (see Set the policy). Nothing was signed.
A challenge that is malformed, oversized, or that carries a digest or an unsupported
credential header fails with challenge_invalid. A sponsored challenge with under 15 seconds left
fails with challenge_expired.
intent: session). Only charge is paid.tempo (evm, stripe, solana, and so on).memo, a digest, and splits.supportedModes without pull) and a zero-amount challenge.Authorization (orPayment-Authorization) and your request already sets it, the payment is refused withpayment_header_conflict.The append-only journal is ~/.termix/x402-payments.jsonl, with owner-only permissions. Before
signing, it atomically reserves the exact amount or upto maximum so concurrent agents cannot
spend the same remaining budget. Invocation IDs and their request fingerprints are recorded inx402-payments.invocations.jsonl beside it, before the first request is sent; a journal moved withTERMIX_X402_JOURNAL_PATH keeps its own invocation journal named after it. Each record is
synced to disk before the next request. Neither file stores request or response content.
termix x402 payments list
termix x402 payments get <paymentId>
termix x402 payments reconcile <paymentId>After the paid request leaves the machine, a timeout, lost response, malformed receipt, or missingupto amount is an unknown outcome. The journal keeps the full maximum reserved and the CLI emitspending: true. payments reconcile checks the transaction or authorization nonce using the
policy's RPC configuration:
expired_unspent and releases the reservation.exact nonce proves the exact charge.upto nonce without a receipt proves money moved but not how much; the maximum stayssettled_amount_unknown.An upto payment whose service reports a successful settlement of zero with no transaction is
recorded as settled for zero, and its response is returned. Nothing re-checks the nonce later, so
the zero is what counts against the spend window and allocation caps.
Session rails (for hosts that build on the payer library) draw payments from a confirmed deposit.
A deposit reserved with a payer funds only that wallet's payments; one recorded without a wallet
(as every deposit was before) funds any payment of its session. A deposit counts once against the
spend window of the rule chosen for it by network and token (the highest-priority enabled rule with
a spend window for that token), while each payment drawn from it is authorized by the rule that
matches its URL and does not count against that rule's spend window again.
Manual resolution is an audited last resort and requires an interactive confirmation:
termix x402 payments resolve <paymentId> \
--settled-amount <atomicUnits> \
--transaction <hash> \
--note 'evidence used to establish the amount'Never manually release a reservation from an unchanged wallet balance alone. A pending transaction
and a failed transaction can look identical until the chain establishes the outcome.
termix task submit pays its own fee, charged once a worker's free submissions to a task are
used up, through the same payment journal. It needs no policy rule and never prompts: it pays only
Termix's own fee scheme, and only to the API the CLI is configured for (TERMIX_API_URL).x402 request never gets this exception. A fee payment is listed by x402 payments list with railtermix-fee and rule termix:first-party, a rule id no policy rule can use.
A submission within the free allowance reads neither the policy nor the payment journal: it
succeeds whatever state they are in. Only a submission that is charged a fee reads the policy and
records the payment, before the fee is signed.
Fees are unbounded unless the policy bounds them. An optional marketplaceFees section sets a
per-payment maximum and a rolling window per network and token, counted over every payment
recorded under rule termix:first-party. A policy with this section is a version 2 policy (see
Initialize Policy):
{
"version": 2,
"networks": { "eip155:8453": { "rpcUrlEnv": "BASE_RPC_URL" } },
"rules": [],
"marketplaceFees": [
{
"network": "eip155:8453",
"asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"maxPerPayment": "1000",
"spendWindow": { "seconds": 86400, "max": "20000" }
}
]
}A fee above maxPerPayment, or one that would take the window past max, is refused withpolicy_denied before anything is signed. A fee on a network and token the section does not name
is not bounded by it. A policy file that exists but cannot be read stops a fee; it does not stop a
submission within the free allowance.
A failed task submit reports the submission's idempotency key. If the network fails after the
fee was sent, the failure is outcome_uncertain with pending: true, the fee payment and the
idempotency key. Whenever the fee was paid and the outcome is unknown (pending: true), find out
what happened before submitting again:
termix task my-submissions to see whether the submission was recorded.termix x402 payments list and look for the fee payment (termix-fee). A settledunknown one may or may not have been.termix x402 payments reconcile <paymentId>. It reads the authorization nonce through thenetworks entry for it.expired_unspent and nothing was charged.Submit again, without a stored key, only when the submission is missing. Re-running task submit
uploads its files again under new keys, so it is never a replay of the earlier request. WithTERMIX_IDEMPOTENCY_KEY set to the reported key, the files are uploaded again but the
submission is sent under that key, and the API refuses it, naming the original intent and its
status, without charging again:idempotency_key_reused past the free allowance, idempotency_key_payload_mismatch within it.
Past the free allowance the CLI has already signed a fee for that request by then, so that payment
stays unknown, with the refusal in its error, until x402 payments reconcile resolves it after
its authorization expires, as above.
Developers can run make smoke x402-pay to verify real exact, partial upto, zero-chargeupto, and nonce-replay behavior on a disposable Base fork without spending real funds.