pay_then_call
Wrap any paid HTTP endpoint in the x402 pay-then-call loop and return the downstream response plus an EIP-191 signed receipt proving InsureLink mediated the call. The signed context envelope contains: { request: {url, method, body_sha256}, payment: {asset, amount, network, settlement_id}, response: {status, sha256, content_type, length}, observed_at, mediator: 'insurelink' } and a signature recoverable to InsureLink's deployer key. Two modes: (a) caller_supplies_payment — pass x_payment_header (base64) so the upstream call is settled by your wallet; (b) mode='quote_only' — return only the 402 quote without paying. Pass idempotency_key to safely retry: identical requests return the cached signed receipt without settling a second payment, and conflicting payloads under the same key are rejected. Use this to give an LLM verifiable provenance for any paid agent call (banking, market data, gov endpoints).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | Target paid endpoint. | |
| body | No | Raw request body. JSON-encode before passing. | |
| mode | No | `quote_only` returns the 402 quote without settling. Default `pay_and_call`. | |
| method | No | HTTP method. Default GET. | |
| headers | No | Extra request headers (Content-Type, Authorization, etc.). | |
| purpose | No | Free-form audit string included in the signed receipt. | |
| agent_wallet | No | Calling agent wallet (logged in the signed receipt for downstream attribution). | |
| idempotency_key | No | Client-supplied idempotency key. If provided, repeated calls with the same key return the cached response and never settle a second payment. A subsequent call with the same key but a different request payload is rejected with `idempotency_key_conflict`. Keys are retained for 24h. | |
| max_amount_usdc | No | Refuse to settle if the 402 quote exceeds this USDC amount. Default 10. | |
| x_payment_header | No | Base64-encoded X-PAYMENT header (caller pre-builds settlement payload). Required unless mode='quote_only'. |