# x402

Two distinct x402 shapes — do not mix them.

## 1. In-session x402 (main agent flow)

1. Agent run hits a payable action
2. Tychi returns `pending_x402`
3. SDK signs EIP-712 locally on the agent's device
4. SDK retries with payment signature
5. SDK resumes the run with the payment result

Helpers:

- `client.x402.sign(pending, password)`
- `client.x402.fetch(pending, paymentSignatureHeader)`
- `client.x402.signFetchAndResume(pending, runId, provider, password)`

Use when Tychi prepared the payable request and waits for local approval.

## 2. External wallet helper

Not an agent run flow. Answer a vendor's 402 challenge directly.

Helpers:

- `signExternalX402Payment(signer, { accepted, resource? })`
- `payVendorAsExternalWallet({ vendorUrl, signer, paymentRequiredHeader })`

Use when you already have a 402 header from a vendor and want to pay without a Tychi run loop.

## RPC (some helpers only)

Token EIP-712 metadata reads may need:

- `TYI_RPC_URL`
- or `TYI_RPC_URL_<chainId>`

Not required for every SDK feature.

## Mental model

| Path           | Flow                                         |
| -------------- | -------------------------------------------- |
| In-session     | Tychi prepares → sign local → resume Tychi   |
| External buyer | Vendor challenge → sign local → retry vendor |
