Metadata-Version: 2.4
Name: satsgate
Version: 0.3.0
Summary: Charge AI agents in Lightning and USDC on the same 402. Payments go straight to your wallet. 500 free unlocks a month.
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/Mike-io-hash/satsgate
Project-URL: Issues, https://github.com/Mike-io-hash/satsgate/issues
Project-URL: Changelog, https://github.com/Mike-io-hash/satsgate/blob/main/CHANGELOG.md
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: satsgate-sdk<0.11,>=0.10.1
Requires-Dist: satsgate-proxy<0.17,>=0.16.0
Requires-Dist: segno>=1.6.0
Provides-Extra: mcp
Requires-Dist: satsgate-mcp<0.15,>=0.14.1; extra == "mcp"
Dynamic: license-file

# satsgate

Charge AI agents in Lightning and USDC on the same 402. Payments go straight to your wallet. 500 free unlocks a month.

No node to run, and no custody: the buyer pays the seller's wallet. After 500 free unlocks in a UTC month, each paid unlock debits 2 sats from a prepaid service balance, capped at 10% of the item price.

`satsgate init` takes a merchant from nothing to a self-hosted paywall config. It opens a free account, saves the account key in `.satsgate/account.env`, asks for a Lightning Address, mints a restricted proxy key, writes `.env` and `satsgate-proxy.yaml`, and checks the paywall with a real 402. That check does not pay, verify, or settle. It also reads whether the Lightning Address advertises LUD-21 verify.

Terms: https://satsgate.org/terms. Source: https://github.com/Mike-io-hash/satsgate. API reference: https://github.com/Mike-io-hash/satsgate/blob/main/docs/api.md.

It does not ask for a seed, a private key, or a recovery phrase. It does not hold sats or USDC. The account key is not copied into the project `.env`. The project `.env` holds `SATSGATE_API_KEY` (`sgr_`) and `SATSGATE_ORIGIN_SECRET`.

```bash
uvx satsgate init
```

or `pip install satsgate`, then `satsgate init`.

Three commands:

- `satsgate try` pays a demo paywall once, to your own Lightning Address, so you see a real 402 paid and unlocked before you configure anything of your own.
- `satsgate init` writes the config for your API or your remote MCP server.
- `satsgate status` reads the setup back.

## Try it

Once you have a Lightning Address, this takes about five minutes:

```bash
uvx satsgate try
```

`try` opens or reuses the free account in `.satsgate/`, sets your Lightning Address, and mints a restricted key for this run only. A demo origin, the proxy, and a buyer run in the same process. Nothing listens on a port. The buyer asks `GET /hello`, gets a 402 for 10 sats (`--sats` sets 1 to 1000), and the terminal shows the invoice and a QR a phone camera can scan (`--no-qr` hides it).

The payment is real. The sats go to your own Lightning Address. Pay from a different wallet than the one behind that address, because some wallets cannot pay their own invoice. When the address advertises LUD-21 verify, `try` sees the payment by itself. Otherwise it asks for the payment preimage from the paying wallet. After the unlock it prints the demo response and the free unlocks left this month, then revokes the restricted key. It writes only under `.satsgate/`.

An agent cannot scan a QR for its owner. It gets the invoice and checks later:

```bash
satsgate try --json --no-wait --lightning-address merchant@pay.example
satsgate try --check <payment_hash> --json
satsgate try --check <payment_hash> --preimage <hex> --json
```

`--no-wait` never prompts, even on a terminal. It returns `status` `awaiting_payment`, the `challenge` (`invoice`, `payment_hash`, `invoice_expires_at`), and a `check_command`. The macaroon stays in `.satsgate/try.json` and is not printed. `--check` reads the status once. While the invoice is unpaid it returns `pending` (with `retry_after_seconds`), `expired`, `preimage_required`, or `preimage_rejected`, and it does not mint a key or use a free unlock. A confirmed payment whose access window ended before it was unlocked returns `expired` with `unlock_window_ended`. Nothing is minted or debited. Once the payment is confirmed, `--check` sends one `GET /hello` through the same in-process proxy as interactive mode, prints the demo origin's response, and uses one free unlock. The core debits that unlock only after the origin answers 2xx, and only once for that payment. A repeat check returns the saved response with `already_unlocked: true` and uses nothing more. The core, not the local file, decides that the payment was already unlocked.

`schema_version` stays 1 and `status` stays `paid`. Inside `paid`: `seconds` (a number, or null on a repeat check), `origin_response` (the demo origin's JSON), `unlocked` (true after a confirmed check or an interactive unlock), `already_unlocked` (true when this payment was already unlocked), and `free_unlocks_left` (an integer, or null when the quota was not read or was not saved). Interactive mode uses the same `paid` fields. `.satsgate/try.json` gains `unlocked`, with `origin_response`, `free_unlocks_left`, and `unlocked_at`. A file written by 0.2.0, without `unlocked`, still unlocks once. If the unlock succeeded and that record was not saved, a later check returns `paid` with `origin_response: null`, `free_unlocks_left: null`, and the warning `origin_response_not_saved`. With `--json` and without `--no-wait`, `try` waits for the payment when the address advertises LUD-21 verify and prints the invoice on stderr; otherwise it returns like `--no-wait`.

## API or MCP

Human mode asks what you are charging for. Agent mode defaults to `--kind api`.

```bash
satsgate init --json --lightning-address merchant@pay.example --kind mcp --paid-tool deep_search=21
```

`--kind mcp` writes one route with `methods: [POST, DELETE]` on `--mcp-path` (default `/mcp`), `signal: in_band`, `default: free`, and one entry per `--paid-tool NAME=SATS`. Only those tools are charged; every other MCP message is forwarded free. The upstream default is `http://127.0.0.1:8000`. Without `--paid-tool`, the route uses `example_tool` at 10 sats and warns `example_tool_placeholder`. The check is an unpaid `tools/call` through the in-memory proxy, and `route` in the JSON lists the tools. The resource of a paid tool is `route:mcp:<tool>`.

## Lightning Address

When the Lightning Address is missing, or does not advertise LUD-21 verify, `init` and `try` list providers that advertised LUD-21 verify on a given date. Human mode prints the list. Agent mode adds `address_options` (`checked_on`, `providers`) and a `next_steps` line. The list is alphabetical and is not an endorsement. It can change: the live check on your own address is what counts. In human mode, `init` offers to try another address after a negative check, up to three times. The YAML does not change.

## Status

```bash
satsgate status
satsgate status --json
satsgate status --check-address
```

`status` shows the account (`key_preview` and fingerprint, never the key), the Lightning Address, the last LUD-21 check from `.satsgate/last-check.json`, the free unlocks left and when they reset, the prepaid balance, paid unlocks in the last 24 hours, the routes from `satsgate-proxy.yaml` with USDC on or off, and whether the proxy answers `GET /healthz` on its local address. `--check-address` checks the address again with one unpaid invoice; nothing is paid or debited. `--config` reads another YAML. Exit codes: 0 fine, 1 the API or the network failed, 2 usage (for example no account here), 3 something needs a decision (no address, an address without LUD-21 verify, a suspended account, USDC on a route without a verified EVM payee, or a rejected key).

## Human and agent

Human mode prompts when stdin is a terminal and `--json` is not set. It asks what you are charging for (API or MCP) and the Lightning Address. With MCP it also asks for the tool to charge for and its price. USDC test mode and the origin snippet are flags (`--want-usdc`, `--framework`). Agent mode (`--json`, or stdin that is not a terminal) never prompts. It prints one JSON object on stdout and notes on stderr. A missing Lightning Address is exit 2 and names `--lightning-address`.

```bash
satsgate init --json --lightning-address merchant@pay.example
satsgate init --json --lightning-address merchant@pay.example --want-usdc
satsgate init --docker --framework fastapi
```

JSON (`schema_version` 1) includes `ok`, `status`, `exit_code`, `api_url`, `kind`, `account` (`client_id`, `key_preview`, `fingerprint`, `reused`), `payee_lightning_address`, `usdc`, `files`, `route`, `test_402`, `lud21`, `address_options`, `start_command`, `next_steps`, `warnings`, and `error`. A key is shown as `sg_…` or `sgr_…` plus the last four characters, and as a fingerprint. The connect link is not a JSON field.

## LUD-21 check

After the test 402, `init` asks the core once for the status of that unpaid test invoice. It is a read: nothing is paid, nothing is debited, and no second invoice is created. The answer shows whether the Lightning Address advertises LUD-21 verify.

- `lud21.supported: true`: a person can pay the QR from any Lightning wallet, and the proxy confirms the payment without a preimage.
- `lud21.supported: false` and the warning `lud21_not_supported`: agents can still pay, because they send the preimage. A person who pays the QR from a wallet that does not show the preimage cannot finish. To accept those payments, use a Lightning Address that advertises LUD-21 verify.
- `lud21.supported: null` and the warning `lud21_not_checked`: the check did not get an answer. Run `satsgate init` again to check.

The check never fails `init` and does not change the exit code. `lud21` is `null` when `init` stopped before the check, for example when the test 402 failed. Human mode prints the same sentence after the Lightning Address.

```json
"lud21": {
  "supported": false,
  "detail": "The Lightning Address does not advertise LUD-21 verify. Agents can still pay: they send the preimage. A person who pays the QR from a wallet that does not show the preimage cannot finish. To accept those payments, use a Lightning Address that advertises LUD-21 verify."
},
"warnings": ["lud21_not_supported"]
```

Exit codes: 0 done, 1 the API or the network failed, 2 usage, 3 a human has to decide, 4 rate-limited. A 429 includes `retry_after_seconds` and is not retried.

## Files

| Path | Mode | Contents |
| --- | --- | --- |
| `.satsgate/` | 0700 | directory |
| `.satsgate/account.env` | 0600 | `SATSGATE_ACCOUNT_KEY` |
| `.satsgate/.gitignore` | | `*` |
| `.env` | 0600 when created here | `SATSGATE_API_KEY`, `SATSGATE_ORIGIN_SECRET` |
| `satsgate-proxy.yaml` | | proxy config, no secrets |
| `.satsgate/connect-link.txt` | 0600 | wallet link in agent mode |
| `.satsgate/last-check.json` | 0600 | last LUD-21 result for `status`; a cache, not listed in `files` |
| `.satsgate/try.json` | 0600 | the pending `try` for `--check`, with its macaroon and, after the unlock, the saved origin response |

A second run reuses the account and the keys. An existing YAML or snippet is not overwritten (agent exit 3 `file_exists`). A different `SATSGATE_*` value is exit 3 `env_conflict`. A symlink is refused. On Windows the run finishes and warns `permissions_not_restricted`; WSL is the supported way to get owner-only files.

## USDC payments: Base network only

USDC payments use Base only. Ethereum mainnet, Polygon, Solana, Arbitrum, and any other chain are not accepted.

| Network | Network id | Circle USDC contract | Status |
| --- | --- | --- | --- |
| Base Sepolia (testnet) | `eip155:84532` | [`0x036CbD53842c5426634e7929541eC2318f3dCF7e`](https://sepolia.basescan.org/token/0x036CbD53842c5426634e7929541eC2318f3dCF7e) | Testing. It is not a network for real buyers. |
| Base | `eip155:8453` | [`0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913`](https://basescan.org/token/0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913) | Live mode (on by default on api.satsgate.org; a self-hosted core needs `SATSGATE_X402_CDP=1` and CDP credentials, see [self-hosting](https://github.com/Mike-io-hash/satsgate/blob/main/docs/self-hosting.md)). |

`payTo` must be an address you control on Base. The USDC moves from the buyer to that address. Satsgate does not hold a buyer wallet and does not run its own facilitator.

When USDC is off, the next steps of a successful `init` include: "To also accept USDC on Base, run satsgate init again with --want-usdc." `--want-usdc` mints a one-time connect link when the EVM payee is not verified yet. A terminal prints the link once and can open it. Otherwise it is written to `.satsgate/connect-link.txt` and is not printed. After the payee is verified, a later run sets `x402: true` and `x402_mode: test`. The unpaid 402 then includes a Base Sepolia offer. Paying that offer is a later step for a buyer agent (`satsgate-mcp-pay`), with the key on the buyer's machine. Test mode is free.

To turn USDC test mode off, delete the YAML and run `init` again. It is regenerated and the keys are reused. Manual edits to the YAML are lost. To keep them, remove the route's `x402` and `x402_mode` lines and restart the proxy instead.

Lightning has no test network. A paid Lightning request moves real sats to the merchant's own address.

## Start

```bash
uvx --env-file .env satsgate-proxy --config satsgate-proxy.yaml
```

`satsgate` 0.3.0. `--docker` writes `docker-compose.satsgate.yml` and prints `docker compose -f docker-compose.satsgate.yml up`. The compose file uses the public image `ghcr.io/mike-io-hash/satsgate-proxy:0.16.0`. The generated service listens on `0.0.0.0`; the YAML written for `uvx` stays on `127.0.0.1`.

## Inside a Python app

A FastAPI or Starlette app can skip the proxy: put `@paid(sats=10)` under the route decorator of each priced route, and add `app = protect(app)`. Both come from `satsgate`. `protect` reads `SATSGATE_API_KEY` from the environment. See [Charge from inside a Python app](https://github.com/Mike-io-hash/satsgate/blob/main/proxy/README.md#charge-from-inside-a-python-app).

## Contributors' note

To build the image yourself, use `proxy/Dockerfile` from the repo. From a checkout: `pip install -e sdk/python -e proxy -e cli`.

`--framework fastapi`, `express`, or `nginx` copies the existing origin check. A client that can reach the origin directly must fail closed. The Caddy file in the package is a note, not an HMAC check.
