How it works

Think of an arcade: put a coin in, play. With x402 Pay-As-You-Go (PAYG) your Solana wallet is the coin.
  1. Put a little SOL into StackNet’s vault.
  2. Get back an API key that’s already loaded with credit.
  3. Every API call spends a bit of it. Top up when it runs low.
No email, no password, no billing page. The key is created on your machine and never sent to a server.
The name comes from HTTP status 402 Payment Required. x402 is the standard that makes “pay for this request” actually work.

Get a key

Call createKeyFromSol again with the same wallet to top up the existing key.

Use the key

It works exactly like a normal API key, just with a pg_ prefix:
PAYG is mainnet-only and payments are real. Keep the key and your wallet secret out of client-side code and public repos.

Building an app on Geoff?

By default any wallet can create a key. If you want your users’ wallets to spend only inside your app, under limits you set, use app invites. Your backend holds a secret app invite key. It hands each wallet a short-lived allow invite, which the wallet redeems (by signing a message) to become enrolled in your app. From then on, that wallet’s keys and balances are scoped to your app: spend-capped, tool-restricted, and isolated from any other app the same wallet uses.
  • Treat wallet + stackId + inviteId as the identity for key lookup and top-ups.
  • Top up the wallet’s existing key (topUpKeyFromSol) instead of minting new ones.
  • The app invite key, allow invites, and pg_ keys are all secrets. Don’t log or persist them.
Requires @stacknet/x402payg 0.3.5 or newer.