Skip to content
Pay.sh is a command-line payment layer for HTTP APIs. A Pay gateway returns an HTTP 402 Payment Required challenge, verifies the client’s payment proof, and then serves or proxies the requested endpoint. It supports pay-per-use endpoints and recurring subscription plans.
Start with --sandbox. It uses an ephemeral, funded local account, so the examples do not spend real funds or require mainnet wallet setup.

​Install Pay

On macOS, install the prebuilt binary with Homebrew:
On Linux and Windows, download the archive for your platform from the latest pay release, extract it, and put the pay binary on your PATH:
The commands on this page need pay 0.29.0 or later. The npm package (npm install --global @solana/pay) also installs a pay binary, but as of October 2026 it downloads pay 0.26.0, which does not have pay gate demo or pay gate scaffold. It still works as the client through npx, for example against the gateway you run in Gate an API:
See the Pay installation guide for platform details, updates, and source installation.

​Try the demo gateway

Start the built-in gateway demo in sandbox mode:
The command prints the local endpoints you can call from another terminal. Use pay curl as the client so it can handle the 402 challenge and retry with a payment proof.

​Gate an API

A paywall specification defines routing, allowed endpoints, pricing, currencies, and operator settings. Scaffold one with:
This minimal sandbox example serves a fixed response and charges one cent per request:
paywall.yml
Run the gateway:
Then compare the unpaid and paid requests from another terminal:
The plain request should receive a 402 response. The Pay client handles the challenge and returns the gateway response after the sandbox payment succeeds. For a real API, change routing.type to proxy, configure the upstream URL, and keep upstream credentials in environment variables. See Write a paywall spec for the complete schema and production routing options.

​Let an agent pay (x402)

Pay can also be the client side for an AI agent. Here an x402-only sandbox API charges a tenth of a cent per request, and Claude Code pays it through Pay’s local tools. The API, payer wallet, and settlement all use the Solana sandbox, so no account or real funds are needed. You need Pay and Claude Code installed. Create x402-demo.yaml. schemes: [x402-exact] under metering makes this an x402-only endpoint:
x402-demo.yaml
Start the API and leave it running. Sandbox mode creates and funds temporary operator and payer accounts automatically:
In another terminal, start Claude Code in sandbox mode:
Pay attaches its local MCP tools to the agent session. The agent does not receive a private key. Paste this prompt into the agent:
The request follows one complete x402 V2 payment loop:
  1. The API returns 402 Payment Required with a PAYMENT-REQUIRED challenge.
  2. Pay validates the x402 requirements and displays the payment terms.
  3. After approval, the sandbox wallet signs and Pay retries the request with PAYMENT-SIGNATURE.
  4. The API returns the result with a PAYMENT-RESPONSE receipt.
No real funds move. Rejecting the approval stops the request. To build an x402 V2 client and resource server yourself, continue with x402 on Solana. To see the same flow without installing anything, step through Call a paid API. To settle x402 payments for other servers, become an x402 facilitator.

​Add a subscription

Use a subscription block instead of metering when access should renew on a fixed period. This endpoint creates a 30-day, 9.99 USDC plan. Subscription endpoints also need a challenge_binding_secret under operator. Generate one with openssl rand -hex 32, paste it in, and keep the same value across restarts: changing it invalidates every open subscription session. Don’t commit it to source control.
monthly.yml
Start the gateway. On first launch, Pay prompts you to publish the subscription plan; sandbox mode covers the account funding.
Call the endpoint twice from another terminal:
Inspect subscriptions associated with the active Pay account:
See the subscription examples for weekly and annual periods, multiple tiers, expiry caps, revenue routing, and cancellation commands.

​Prepare for production

Sandbox and production use different accounts and networks. Before accepting real payments:
  1. Read the provider deployment guide.
  2. Configure a mainnet operator, recipient, signer, and fee payer explicitly.
  3. Use routing.type: proxy for the real upstream service and allow only the endpoints you intend to expose.
  4. Keep signing material and upstream API credentials out of the YAML file and source control.
  5. Test challenge handling, settlement, retries, and failure responses before publishing the endpoint.
Run pay --help and the relevant subcommand’s --help output for the exact flags supported by your installed version.