{
  "openapi": "3.0.3",
  "info": {
    "title": "TunnelSats API",
    "version": "1.14.0",
    "description": "\n<Frame caption=\"Hybrid Lightning Privacy\nPre-configured WireGuard VPN tunnels for your Lightning Node.\nKeep your IP hidden. Route clearnet safely. No KYC.\">\n  ![](https://api.eu.apidog.com/api/v1/projects/361232/resources/339386/image-preview)\n</Frame>\n\n# TunnelSats API\n\nProgrammatic access to TunnelSats VPN subscriptions.\n\n## ⚡ Quick Start\n\n1. **List Servers**: `GET /servers` - See available locations.\n    \n2. **Create Subscription**: `POST /create` - Get a Lightning invoice.\n    \n3. **Pay**: Pay the invoice with any Lightning wallet.\n    \n4. **Claim**: `POST /claim` - Receive your WireGuard config.\n    \n5. **Switch Region ($1.00)**: `POST /migrate/check` -> `POST /migrate` -> `POST /migrate/claim` (3-day + 2 GB parallel cutover grace window).\n\n## 💰 Pricing\n\n| Duration | Price | Discount |\n| --- | --- | --- |\n| 1 month | $3.00 | \\- |\n| 3 months | $8.55 | 5% |\n| 6 months | $16.20 | 10% |\n| 12 months | $28.80 | **20%** |\n\n_Prices converted to Sats at current BTC/USD rate._\n\n## 🆔 Server IDs\n\n| ID | Location |\n| --- | --- |\n| `us-east` | Ashburn, USA |\n| `us-west` | Hillsboro, USA |\n| `eu-de` | Nuremberg, DE |\n| `eu-ch` | Geneva, CH |\n| `asia-sg` | Singapore |\n| `sa-br` | Sao Paulo, BR |\n| `oc-au` | Sydney, AU |\n\n## 🎁 Referral Program\n\nInclude `referralCode` in `/create` for bonus months:\n\n- 3mo plan → +1 month free\n    \n- 6mo plan → +2 months free\n    \n- 12mo plan → +3 months free\n    \n\n## 🔐 Authentication\n\n**Most endpoints are public** - no auth needed to buy!\n\n**For account endpoints** (`List My Subs`, `Sync`) and `$1.00` **Region Switch** (`POST /migrate`):\n\n| Method | Header / Body Field | How to Get |\n| --- | --- | --- |\n| **API Key** (recommended) | `Authorization: Bearer sk_live_...` | Dashboard → Settings → API Keys |\n| **NIP-98** (advanced) | `Authorization: Nostr` | Nostr Kind 27235 signed event (`payload` SHA-256 tag required on `POST /migrate`) |\n| **X25519 Ownership Proof** (`POST /migrate`) | `proof: \"x25519:<base64>\"` + `challengeWindow` | Local X25519 DH between source private key and `/migrate/check` `challengePubKey` |\n\n## ❓ FAQ\n\n**Q: Do I need an API Key to buy a subscription?**  \nA: No! The purchase flow is completely public. Keys are only for managing your account.\n\n**Q: Where do I get an API Key?**  \nA: Log in at tunnelsats.com → Dashboard → Settings → Generate API Key.\n\n**Q: What's the difference between API Key and NIP-98?**  \nA: API Keys are simple Bearer tokens. NIP-98 uses Nostr-signed events - useful for Nostr-native apps but requires cryptographic signing.\n\n**Q: Can I use my own WireGuard keys?**  \nA: Yes! Pass `wgPublicKey` in `/create` and `/claim` (and `newWgPublicKey` in `/migrate`) to keep your private keys strictly on your own device.\n\n## ⏱️ Rate Limits\n\n- Reads: 60/min (region-switch hash polling: 30/min)\n    \n- Creates / Resets / Region Switches: 10/min (plus 5 failed X25519 proofs/hr per source key)\n    \n- Claims: 10/min\n    \n\n## 🖥️ Base URL\n\nhttps://tunnelsats.com",
    "summary": "What is TunnelSats?\n\nTunnelSats provides pre-configured WireGuard VPN tunnels designed for Lightning Network nodes. It hides your node's IP, enables safe clearnet routing, and requires no KYC – just pay with Lightning.\n\nThis API enables developers to:\n1) Programmatically provision VPN subscriptions for node operators\n2) Integrate VPN management into node management software (Umbrel, Start9, etc.)\n3) Automate renewals for uninterrupted privacy",
    "contact": {
      "name": "Tunnelsats",
      "email": "info@tunnelsats.com",
      "url": "https://tunnelsats.com"
    }
  },
  "x-service-info": {
    "categories": [
      "vpn",
      "networking",
      "bitcoin-lightning",
      "security"
    ],
    "docs": {
      "homepage": "https://tunnelsats.com",
      "apiReference": "https://api.tunnelsats.com",
      "llms": "https://tunnelsats.com/llms.txt",
      "auth": "https://tunnelsats.com/auth.md"
    }
  },
  "servers": [
    {
      "url": "https://tunnelsats.com",
      "description": "Production"
    }
  ],
  "tags": [
    {
      "name": "📡 Discovery",
      "description": "Server discovery and health check endpoints."
    },
    {
      "name": "⚡ Purchase",
      "description": "The happy path: create an invoice, poll for payment, claim your WireGuard config."
    },
    {
      "name": "🔄 Lifecycle",
      "description": "Subscription management: status checks, renewals, syncs, and bandwidth top-ups."
    },
    {
      "name": "🔑 Account",
      "description": "Authenticated endpoints for managing your TunnelSats account: subscriptions and the referral program."
    },
    {
      "name": "🔧 Tools",
      "description": "Lightning Network utility tools for node operators."
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Authenticate using your TunnelSats API Key (sk_live_...)."
      },
      "NostrAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "NIP-98 Nostr Authentication. The token is the base64-encoded NIP-98 event JSON."
      },
      "L402Auth": {
        "type": "apiKey",
        "in": "header",
        "name": "Authorization",
        "description": "Lightning HTTP 402 (L402) Authentication: Authorization: L402 <macaroon>:<preimage>."
      }
    },
    "schemas": {
      "ApiError": {
        "type": "object",
        "required": [
          "error",
          "message"
        ],
        "properties": {
          "error": {
            "type": "string",
            "example": "ERR_RATE_LIMIT_EXCEEDED",
            "description": "Standard machine-readable error code."
          },
          "message": {
            "type": "string",
            "example": "Rate limit exceeded. Please wait before retrying.",
            "description": "Human-readable error explanation."
          },
          "details": {
            "type": "object",
            "nullable": true,
            "description": "Optional validation error details or parameters."
          },
          "reason": {
            "type": "string",
            "description": "Stable, sanitized reason for the failure."
          },
          "retryable": {
            "type": "boolean"
          },
          "operatorActionRequired": {
            "type": "boolean"
          },
          "resetsThisMonth": {
            "type": "integer",
            "minimum": 0,
            "description": "Shared held monthly reset/switch slots, including unpaid reservations."
          },
          "maxResetsPerMonth": {
            "type": "integer"
          }
        }
      },
      "Server": {
        "type": "object",
        "required": [
          "id",
          "country",
          "city",
          "flag",
          "status",
          "domain"
        ],
        "properties": {
          "id": {
            "type": "string",
            "example": "eu-de",
            "description": "Unique identifier for the server location (group ID, Upptime ID, or specific domain)."
          },
          "country": {
            "type": "string",
            "example": "Germany"
          },
          "city": {
            "type": "string",
            "example": "Nuremberg"
          },
          "flag": {
            "type": "string",
            "example": "🇩🇪"
          },
          "status": {
            "type": "string",
            "enum": [
              "online",
              "offline",
              "degraded"
            ],
            "example": "online"
          },
          "domain": {
            "type": "string",
            "example": "de2.tunnelsats.com"
          },
          "upptimeId": {
            "type": "string",
            "example": "de2"
          },
          "hasDualKeySupport": {
            "type": "boolean",
            "example": true
          }
        }
      },
      "InvoiceOrder": {
        "type": "object",
        "required": [
          "invoice",
          "paymentHash",
          "amountSats",
          "orderId"
        ],
        "properties": {
          "invoice": {
            "type": "string",
            "example": "lnbc41130n1p5a4p2dpp5pwd0d2ua837kz...",
            "description": "BOLT11 Lightning Invoice string to be paid."
          },
          "paymentHash": {
            "type": "string",
            "example": "0b9af6ab9d3c7d6146e3f28ca11bf4b830f4cab95330c5a5c9b25b7827afc44c",
            "description": "SHA256 Payment hash of the invoice."
          },
          "amountSats": {
            "type": "integer",
            "example": 4113,
            "description": "Price in satoshis (dynamically calculated from real-time BTC/USD rate)."
          },
          "orderId": {
            "type": "string",
            "format": "uuid",
            "example": "ab897fc4-41ff-4a55-9bb6-0ce1623e7a87",
            "description": "Unique order identifier for tracking."
          }
        }
      },
      "RenewalOrder": {
        "type": "object",
        "required": [
          "invoice",
          "paymentHash",
          "oldExpiry",
          "newExpiry",
          "renewalId"
        ],
        "properties": {
          "invoice": {
            "type": "string",
            "example": "lnbc30000n1p...",
            "description": "BOLT11 Lightning invoice to be paid for renewal."
          },
          "paymentHash": {
            "type": "string",
            "example": "b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3",
            "description": "Payment hash for renewal tracking."
          },
          "oldExpiry": {
            "type": "string",
            "format": "date-time",
            "example": "2026-09-15T12:00:00Z"
          },
          "newExpiry": {
            "type": "string",
            "format": "date-time",
            "example": "2026-12-15T12:00:00Z"
          },
          "renewalId": {
            "type": "string",
            "format": "uuid",
            "example": "f47ac10b-58cc-4372-a567-0e02b2c3d479"
          }
        }
      },
      "BandwidthResetResponse": {
        "type": "object",
        "required": [
          "invoice",
          "paymentHash",
          "resetId",
          "amountSats",
          "amountUsd",
          "currentUsagePercent",
          "resetsThisMonth",
          "maxResetsPerMonth",
          "expiresAt"
        ],
        "properties": {
          "invoice": {
            "type": "string",
            "example": "lnbc30000n1p...",
            "description": "BOLT11 Lightning invoice for $1 USD equivalent in sats."
          },
          "paymentHash": {
            "type": "string",
            "example": "c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4",
            "description": "Payment hash to track settlement."
          },
          "resetId": {
            "type": "string",
            "format": "uuid",
            "example": "d7b2277f-5990-4721-a565-6816babadc59",
            "description": "UUID tracking the pending bandwidth reset."
          },
          "amountSats": {
            "type": "integer",
            "example": 3000,
            "description": "Dynamic satoshi amount ($1.00 USD)."
          },
          "amountUsd": {
            "type": "string",
            "example": "1.00",
            "description": "Fixed USD price ($1.00)."
          },
          "currentUsagePercent": {
            "type": "string",
            "example": "85.4",
            "description": "Bandwidth usage percentage when the invoice was requested, for information only: a reset is available at any usage."
          },
          "resetsThisMonth": {
            "type": "integer",
            "example": 0,
            "description": "Consumed paid bandwidth resets and committed region switches this UTC calendar month across the subscription lineage. The legacy field name is retained."
          },
          "maxResetsPerMonth": {
            "type": "integer",
            "example": 2,
            "description": "Shared monthly limit for paid bandwidth resets and region switches across the subscription lineage."
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time",
            "example": "2026-09-27T11:00:00.000Z",
            "description": "Conservative UTC invoice-expiry upper bound, including provider-response latency. The provider invoice may expire earlier; its monthly slot is retained through this deadline and released only after verified nonpayment. For an eligible open invoice, a repeated request returns this same invoice instead of reserving another slot."
          }
        }
      },
      "SubscriptionStatus": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "status"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "unpaid",
              "pending",
              "paid",
              "claimed",
              "expired",
              "failed",
              "active"
            ],
            "example": "paid"
          },
          "paymentHash": {
            "type": "string",
            "example": "0b9af6ab9d3c7d6146e3f28ca11bf4b830f4cab95330c5a5c9b25b7827afc44c"
          },
          "serverId": {
            "type": "string",
            "nullable": true,
            "example": "eu-de"
          },
          "duration": {
            "type": "integer",
            "nullable": true,
            "example": 1
          },
          "isProvisioned": {
            "type": "boolean",
            "example": false
          },
          "message": {
            "type": "string",
            "example": "Renewal payment confirmed."
          },
          "subscriptionEnd": {
            "type": "string",
            "format": "date-time",
            "example": "2026-10-15T12:00:00Z",
            "nullable": true
          },
          "bandwidthUsed": {
            "type": "number",
            "example": 45000,
            "description": "Bandwidth used, in decimal megabytes (1 MB = 1,000,000 bytes) as the VPN server counts it.",
            "nullable": true
          },
          "server": {
            "type": "object",
            "nullable": true,
            "additionalProperties": false,
            "properties": {
              "id": {
                "type": "string",
                "example": "us-east"
              },
              "domain": {
                "type": "string",
                "example": "us3.tunnelsats.com"
              },
              "endpoint": {
                "type": "string",
                "example": "us3.tunnelsats.com:51820"
              }
            }
          }
        }
      },
      "PublicKeyStatusResponse": {
        "type": "object",
        "required": [
          "expiry",
          "bandwidth_used_gb",
          "status",
          "server_domain",
          "bandwidth_limit_gb",
          "bandwidth_resets_this_month",
          "max_resets_per_month",
          "vpn_port"
        ],
        "properties": {
          "expiry": {
            "type": "string",
            "format": "date-time",
            "example": "2026-10-15T12:00:00Z",
            "description": "Subscription end date. For a migrated source key this is the recorded grace expiry (falling back to its original expiry if unavailable), not the active destination subscription expiry."
          },
          "bandwidth_used_gb": {
            "type": "number",
            "example": 45.67,
            "description": "Bandwidth consumed, in decimal GB (1 GB = 1,000 MB, as the VPN server counts it). For migrated source keys this is the source usage snapshot captured for the switch, not a live measurement."
          },
          "bandwidth_limit_gb": {
            "type": "number",
            "example": 100,
            "description": "Monthly bandwidth quota of the subscription, in decimal GB (1 GB = 1,000 MB). For migrated source keys this is the recorded grace cap, falling back to the original source allowance (0 means unlimited)."
          },
          "bandwidth_resets_this_month": {
            "type": "integer",
            "minimum": 0,
            "example": 1,
            "description": "Shared paid reset/region-switch slots held this UTC calendar month across the full subscription lineage, including ancestor keys: consumed operations, paid operations being applied or retained after failure, unpaid invoices and provisional reservations. Age alone does not release an uncertain invoice-creation reservation; expired attached invoices release only after LNBits confirms nonpayment. This is the exact count `POST /subscription/bandwidth-reset` compares against `max_resets_per_month`: once `bandwidth_resets_this_month >= max_resets_per_month` it answers 429, unless one of these slots is an open reset invoice, which it then returns again (and, independently, 429 in the last ~90 seconds of a UTC month, when no invoice could expire inside the month). An invoice holds its slot until it is consumed or verified expired and unpaid; requesting the same reset again returns its open reset invoice instead of using another slot. Migrated source responses count retained lineage slots locally without reconciling expired invoices against LNBits."
          },
          "max_resets_per_month": {
            "type": "integer",
            "minimum": 1,
            "example": 2,
            "description": "Maximum bandwidth resets per UTC calendar month."
          },
          "status": {
            "type": "string",
            "enum": [
              "enabled",
              "disabled"
            ],
            "example": "enabled",
            "description": "WireGuard peer status. Committed region-switch source keys always report disabled so reminder clients suppress old-key expiry and bandwidth alerts, even while the source peer remains enabled during grace. This also applies after deletion and on committed cleanup failure."
          },
          "server_domain": {
            "type": "string",
            "example": "de2.tunnelsats.com",
            "description": "Hosting VPN server domain. For a migrated source key this remains its old source domain."
          },
          "vpn_port": {
            "type": "integer",
            "nullable": true,
            "minimum": 1,
            "maximum": 65535,
            "example": 24556,
            "description": "Forwarded port of this subscription on `server_domain` (announce `<server_domain>:<vpn_port>` to the Lightning network), read live from the VPN server. For a disabled key it is the retained port that re-enabling restores. `null` when it is unknown right now: the server has no port forward for the key, holds several candidates, or the port lookup failed. Keep your stored port when it is `null`. Always null for a migrated source key; do not announce or re-enable that retired peer."
          },
          "last_synced_at": {
            "type": "string",
            "format": "date-time",
            "example": "2026-09-01T12:00:00Z",
            "nullable": true,
            "description": "Last sync timestamp. For migrated source keys this is the switch commit timestamp for the journal snapshot; no live gateway sync is performed."
          },
          "migrated_to_server_domain": {
            "type": "string",
            "example": "ch1.tunnelsats.com",
            "description": "Present only for a committed region-switch source key. The recorded immediate destination of that switch, not necessarily the current gateway after further switches. Suppress old-key reminders and ask the user to /link their new public key. No destination public key or secret is returned."
          },
          "grace_expires_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "example": "2026-11-07T12:00:00Z",
            "description": "Present only for a committed region-switch source key. Recorded end of the old source peer grace window; null if unavailable. Its disabled status is permanent and does not depend on this timestamp being in the past."
          }
        }
      },
      "ClaimResult": {
        "type": "object",
        "required": [
          "status"
        ],
        "properties": {
          "config": {
            "type": "string",
            "example": "[Interface]\nPrivateKey = ...\nAddress = 10.9.0.2/32\nDNS = 1.1.1.1\n\n[Peer]\nPublicKey = ...\nEndpoint = de2.tunnelsats.com:51820\nAllowedIPs = 0.0.0.0/0",
            "description": "WireGuard configuration file contents (legacy orders on already_processed only)."
          },
          "fullConfig": {
            "type": "string",
            "nullable": true,
            "description": "Full dual-key WireGuard config (if applicable)."
          },
          "status": {
            "type": "string",
            "enum": [
              "success",
              "already_processed"
            ],
            "example": "success"
          },
          "subscriptionEnd": {
            "type": "string",
            "format": "date-time",
            "example": "2027-01-01T00:00:00.000Z"
          },
          "server": {
            "type": "object",
            "properties": {
              "endpoint": {
                "type": "string",
                "example": "de2.tunnelsats.com:51820"
              },
              "publicKey": {
                "type": "string",
                "description": "Server WireGuard public key."
              },
              "allowedIPs": {
                "type": "string",
                "example": "0.0.0.0/0, ::/0"
              }
            }
          },
          "peer": {
            "type": "object",
            "properties": {
              "address": {
                "type": "string",
                "example": "10.9.0.7",
                "description": "Tunnel IP of your interface."
              },
              "publicKey": {
                "type": "string",
                "description": "Echo of your registered public key (client-held key orders)."
              },
              "presharedKey": {
                "type": "string",
                "description": "Server-generated preshared key."
              }
            }
          },
          "vpnPort": {
            "type": "integer",
            "example": 24556,
            "description": "Public port forwarded to your node through the tunnel."
          }
        },
        "description": "Legacy orders return `config`/`fullConfig`. Orders created with a wgPublicKey return only `server`, `peer` and `vpnPort`; `config` is absent and `fullConfig` is null."
      },
      "SubscriptionListItem": {
        "type": "object",
        "properties": {
          "payment_hash": {
            "type": "string",
            "example": "a1b2c3d4e5f6...",
            "description": "Payment hash (snake_case in list responses)."
          },
          "server_domain": {
            "type": "string",
            "example": "de2.tunnelsats.com"
          },
          "subscription_end": {
            "type": "string",
            "format": "date-time",
            "example": "2026-10-15T12:00:00Z"
          },
          "status": {
            "type": "string",
            "example": "paid"
          },
          "bandwidth_used_gb": {
            "type": "number",
            "example": 12.5,
            "nullable": true
          },
          "bandwidth_resets_this_month": {
            "type": "integer",
            "minimum": 0,
            "example": 1,
            "description": "Shared paid reset/region-switch slots held this UTC calendar month across this subscription's migration lineage, the same count as `bandwidth_resets_this_month` on `POST /subscription/status`. A reset request answers 429 once this reaches `max_resets_per_month`, unless one of the slots is an open reset invoice it can return, or an expired invoice verified unpaid that it can release (see `bandwidth_resets_unpaid`). Omitted when the subscription has no key yet."
          },
          "bandwidth_resets_unpaid": {
            "type": "integer",
            "minimum": 0,
            "example": 0,
            "description": "How many of `bandwidth_resets_this_month` are unpaid reset or region-switch invoices. A repeated reset request reuses its open reset invoice; expired reset or switch invoices release only after verified nonpayment. An open switch invoice is not reused as a reset invoice. Omitted when the subscription has no key yet."
          },
          "max_resets_per_month": {
            "type": "integer",
            "minimum": 1,
            "example": 2,
            "description": "Maximum bandwidth resets per UTC calendar month. Omitted when the subscription has no key yet."
          },
          "region_switch": {
            "type": "object",
            "description": "Safe dashboard discovery for the current subscription. No configuration or secrets are included. Recovery always rechecks current ownership and the current destination. Available independently of creation gates and monthly quota.",
            "required": [
              "quota_month",
              "creation_available",
              "creation_reason",
              "migration"
            ],
            "properties": {
              "quota_month": {
                "type": "string",
                "pattern": "^[0-9]{4}-[0-9]{2}$",
                "description": "UTC month for the accompanying shared quota snapshot."
              },
              "creation_available": {
                "type": "boolean",
                "description": "Server creation gates only; live eligibility, health and quota are checked before invoicing."
              },
              "creation_reason": {
                "type": "string",
                "nullable": true,
                "enum": [
                  "feature_disabled",
                  "maintenance",
                  "settlement_unavailable",
                  "cleanup_unverified",
                  null
                ]
              },
              "migration": {
                "type": "object",
                "nullable": true,
                "description": "Current committed destination during its source grace window; null if absent, expired, cleaned or superseded. Client-held records never advertise Web configuration recovery.",
                "required": [
                  "id",
                  "source_domain",
                  "target_domain",
                  "grace_expires_at",
                  "key_mode",
                  "recovery_available"
                ],
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "source_domain": {
                    "type": "string"
                  },
                  "target_domain": {
                    "type": "string"
                  },
                  "grace_expires_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "key_mode": {
                    "type": "string",
                    "enum": [
                      "web",
                      "client_held"
                    ]
                  },
                  "recovery_available": {
                    "type": "boolean"
                  }
                }
              },
              "pending": {
                "type": "object",
                "nullable": true,
                "description": "Current-source open switch or held failure. Allows the dashboard to resume or inspect an existing switch independently of new-invoice gates and full quota. Contains no invoice capability or draft key material.",
                "required": [
                  "id",
                  "status"
                ],
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "reserving",
                      "pending",
                      "processing",
                      "failed",
                      "failed_cleanup"
                    ]
                  }
                }
              }
            }
          }
        }
      },
      "ReferralCode": {
        "type": "object",
        "required": [
          "code",
          "created_at",
          "usage_count"
        ],
        "properties": {
          "code": {
            "type": "string",
            "example": "REF-7K2Q9Z",
            "description": "Your referral code: `REF-` followed by 6 characters from A-Z and 0-9."
          },
          "created_at": {
            "type": "string",
            "example": "2026-01-15 09:30:00",
            "description": "Creation time in UTC, formatted `YYYY-MM-DD HH:MM:SS`."
          },
          "usage_count": {
            "type": "integer",
            "minimum": 0,
            "example": 3,
            "description": "Paid 3, 6 or 12-month orders that used this code, counted once per order when it is paid, whichever path settles it (payment webhook, status polling, `/claim` or the web checkout). Self-referrals are not counted. Referrals whose bonus was forfeited (no subscription to extend) are counted. Orders settled through the payment webhook or status polling before exactly-once crediting was introduced were never counted and are not added retroactively."
          }
        }
      },
      "ReferralHistory": {
        "type": "object",
        "required": [
          "history"
        ],
        "properties": {
          "history": {
            "type": "array",
            "maxItems": 50,
            "description": "Paid or claimed subscriptions that used your code, newest first.",
            "items": {
              "type": "object",
              "required": [
                "date",
                "duration_purchased",
                "bonus_earned",
                "bonus_status"
              ],
              "properties": {
                "date": {
                  "type": "string",
                  "example": "2026-01-01 19:40:00",
                  "description": "When the referred order was created, in UTC, formatted `YYYY-MM-DD HH:MM:SS`."
                },
                "duration_purchased": {
                  "type": "integer",
                  "example": 3,
                  "description": "Purchased subscription length in months (1, 3, 6 or 12)."
                },
                "bonus_earned": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 3,
                  "example": 1,
                  "description": "Bonus months this referral qualifies for (1 → 0, 3 → 1, 6 → 2, 12 → 3). They are credited once, when the referred order is paid, to your latest subscription that is active or expired less than 30 days ago; without one the bonus is forfeited."
                },
                "bonus_status": {
                  "type": "string",
                  "enum": [
                    "credited",
                    "pending",
                    "forfeited",
                    "skipped",
                    "legacy",
                    "failed"
                  ],
                  "example": "credited",
                  "description": "Settlement state of the referrer bonus for this order: `credited` (applied to your subscription), `pending` (settled order not yet evaluated or extension in flight), `forfeited` (eligible, but you had no active or recently expired subscription to extend), `skipped` (not eligible for a referrer bonus, see `bonus_reason`), `legacy` (settled before per-order bonus tracking existed), or `failed` (operational failure during extension; alerted to operators)."
                },
                "bonus_reason": {
                  "type": "string",
                  "enum": [
                    "no_active_subscription",
                    "self_referral",
                    "not_eligible"
                  ],
                  "example": "no_active_subscription",
                  "description": "Present when `bonus_status` is `forfeited` (`no_active_subscription`) or `skipped` (`self_referral` when the buyer authenticated as the code owner, or `not_eligible` for 1-month plans)."
                }
              }
            }
          }
        }
      },
      "SyncResult": {
        "type": "object",
        "required": [
          "success"
        ],
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "subscription": {
            "type": "object",
            "description": "Updated subscription data from VPN server.",
            "properties": {
              "expiry": {
                "type": "string",
                "format": "date-time",
                "example": "2026-10-15T12:00:00Z"
              },
              "bandwidth_used_gb": {
                "type": "number",
                "example": 45.67
              },
              "status": {
                "type": "string",
                "example": "enabled"
              },
              "server_domain": {
                "type": "string",
                "example": "de2.tunnelsats.com"
              }
            }
          }
        }
      },
      "NodeLookup": {
        "type": "object",
        "description": "The result of a network address discovery for a Lightning node.",
        "required": [
          "addresses"
        ],
        "properties": {
          "addresses": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "example": [
              "203.0.113.42:9735",
              "[2001:db8::1]:9735"
            ],
            "description": "List of discovered public network addresses (IPv4, IPv6, or Tor) for the node."
          }
        }
      },
      "ConnectivityResult": {
        "type": "object",
        "description": "The result of a ping or connectivity test against a specific Lightning node endpoint.",
        "required": [
          "success",
          "reachable",
          "latencyMs",
          "message"
        ],
        "properties": {
          "success": {
            "type": "boolean",
            "example": true,
            "description": "True if the test logic successfully executed."
          },
          "reachable": {
            "type": "boolean",
            "example": true,
            "description": "True if the target node actually responded to the connection attempt."
          },
          "latencyMs": {
            "type": "integer",
            "example": 35,
            "description": "Estimated round-trip time in milliseconds."
          },
          "message": {
            "type": "string",
            "example": "Connection successful",
            "description": "A human-readable result message or technical error detail from the probe."
          }
        }
      },
      "BandwidthResetPaymentStatus": {
        "type": "object",
        "required": [
          "paymentHash",
          "type",
          "status",
          "resetId",
          "expiresAt",
          "message"
        ],
        "properties": {
          "paymentHash": {
            "type": "string",
            "example": "c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4"
          },
          "type": {
            "type": "string",
            "enum": [
              "bandwidth_reset"
            ],
            "description": "Distinguishes a bandwidth-reset payment from a subscription order or renewal."
          },
          "status": {
            "type": "string",
            "enum": [
              "unpaid",
              "processing",
              "paid",
              "failed",
              "expired"
            ],
            "description": "unpaid: waiting for payment. processing (HTTP 202): paid, reset being applied; poll again. paid: the reset was applied. failed: paid, but the reset could not be applied; contact support with the payment hash. expired: the invoice expired unpaid."
          },
          "resetId": {
            "type": "string",
            "format": "uuid",
            "example": "d7b2277f-5990-4721-a565-6816babadc59"
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "example": "2026-09-27T11:00:00.000Z"
          },
          "message": {
            "type": "string",
            "example": "Bandwidth reset applied."
          }
        }
      },
      "RegionSwitchServer": {
        "type": "object",
        "required": [
          "id",
          "domain",
          "country",
          "city",
          "flag"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "domain": {
            "type": "string"
          },
          "country": {
            "type": "string"
          },
          "city": {
            "type": "string"
          },
          "flag": {
            "type": "string"
          }
        }
      },
      "RegionSwitchCheckResult": {
        "type": "object",
        "required": [
          "eligible",
          "reason",
          "currentServer",
          "subscriptionEnd",
          "resetsThisMonth",
          "maxResetsPerMonth",
          "remainingSlots",
          "grace"
        ],
        "properties": {
          "eligible": {
            "type": "boolean"
          },
          "reason": {
            "type": "string",
            "nullable": true
          },
          "currentServer": {
            "$ref": "#/components/schemas/RegionSwitchServer"
          },
          "subscriptionEnd": {
            "type": "string",
            "format": "date-time"
          },
          "resetsThisMonth": {
            "type": "integer",
            "minimum": 0,
            "description": "Shared held monthly reset/switch slots, including unpaid reservations."
          },
          "maxResetsPerMonth": {
            "type": "integer",
            "enum": [
              2
            ]
          },
          "remainingSlots": {
            "type": "integer",
            "minimum": 0,
            "maximum": 2
          },
          "grace": {
            "type": "object",
            "required": [
              "maxHours",
              "additionalMb",
              "cappedAtSourceAllowance",
              "unlimited"
            ],
            "properties": {
              "maxHours": {
                "type": "integer",
                "enum": [
                  72
                ]
              },
              "additionalMb": {
                "type": "integer",
                "enum": [
                  2000
                ]
              },
              "cappedAtSourceAllowance": {
                "type": "boolean"
              },
              "unlimited": {
                "type": "boolean"
              }
            }
          },
          "challengePubKey": {
            "type": "string",
            "minLength": 44,
            "maxLength": 44,
            "pattern": "^[A-Za-z0-9+/]{43}=$",
            "description": "Canonical 32-byte X25519 WireGuard public key; weak/low-order points are rejected."
          },
          "challengeWindow": {
            "type": "integer",
            "minimum": 1,
            "description": "Opaque numeric issuance identifier; echo unchanged with the proof."
          },
          "challengeExpiresAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "RegionSwitchInvoice": {
        "type": "object",
        "required": [
          "invoice",
          "paymentHash",
          "migrationId",
          "amountSats",
          "amountUsd",
          "expiresAt",
          "resetsThisMonth",
          "maxResetsPerMonth"
        ],
        "properties": {
          "invoice": {
            "type": "string",
            "description": "BOLT11 Lightning invoice."
          },
          "paymentHash": {
            "type": "string",
            "minLength": 64,
            "maxLength": 64,
            "pattern": "^[a-fA-F0-9]{64}$"
          },
          "migrationId": {
            "type": "string",
            "format": "uuid"
          },
          "amountSats": {
            "type": "integer",
            "minimum": 1
          },
          "amountUsd": {
            "type": "string",
            "enum": [
              "1.00"
            ]
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "resetsThisMonth": {
            "type": "integer",
            "minimum": 0,
            "description": "Shared held monthly reset/switch slots, including unpaid reservations."
          },
          "maxResetsPerMonth": {
            "type": "integer",
            "enum": [
              2
            ]
          }
        }
      },
      "RegionSwitchClaimResult": {
        "type": "object",
        "required": [
          "status",
          "subscriptionEnd",
          "server",
          "peer",
          "vpnPort",
          "keyId",
          "graceExpiresAt",
          "fullConfig"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "success",
              "already_processed"
            ]
          },
          "subscriptionEnd": {
            "type": "string",
            "format": "date-time"
          },
          "server": {
            "type": "object",
            "required": [
              "endpoint",
              "publicKey",
              "allowedIPs"
            ],
            "properties": {
              "endpoint": {
                "type": "string"
              },
              "publicKey": {
                "type": "string",
                "minLength": 44,
                "maxLength": 44,
                "pattern": "^[A-Za-z0-9+/]{43}=$",
                "description": "Canonical 32-byte X25519 WireGuard public key; weak/low-order points are rejected."
              },
              "allowedIPs": {
                "type": "string",
                "enum": [
                  "0.0.0.0/0, ::/0"
                ]
              }
            }
          },
          "peer": {
            "type": "object",
            "required": [
              "address",
              "publicKey",
              "presharedKey"
            ],
            "properties": {
              "address": {
                "type": "string",
                "description": "Destination IPv4 interface address with /32 prefix."
              },
              "publicKey": {
                "type": "string",
                "minLength": 44,
                "maxLength": 44,
                "pattern": "^[A-Za-z0-9+/]{43}=$",
                "description": "Canonical 32-byte X25519 WireGuard public key; weak/low-order points are rejected."
              },
              "presharedKey": {
                "type": "string",
                "description": "Sensitive server-generated PSK. Store securely and never log it."
              }
            }
          },
          "vpnPort": {
            "type": "integer",
            "minimum": 1,
            "maximum": 65535
          },
          "keyId": {
            "type": "string"
          },
          "graceExpiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "fullConfig": {
            "type": "string",
            "nullable": true,
            "description": "Always null. Build the config locally using your retained replacement private key."
          }
        }
      },
      "RegionSwitchPaymentStatus": {
        "type": "object",
        "required": [
          "type",
          "paymentHash",
          "migrationId",
          "expiresAt",
          "status",
          "isProvisioned",
          "retryable"
        ],
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "region_switch"
            ]
          },
          "paymentHash": {
            "type": "string",
            "minLength": 64,
            "maxLength": 64,
            "pattern": "^[a-fA-F0-9]{64}$"
          },
          "migrationId": {
            "type": "string",
            "format": "uuid"
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "status": {
            "type": "string",
            "enum": [
              "unpaid",
              "processing",
              "paid",
              "failed",
              "expired"
            ]
          },
          "isProvisioned": {
            "type": "boolean"
          },
          "retryable": {
            "type": "boolean"
          },
          "reason": {
            "type": "string"
          },
          "operatorActionRequired": {
            "type": "boolean"
          }
        }
      }
    },
    "responses": {
      "Payment Required": {
        "description": "",
        "content": {
          "application/json": {
            "schema": {
              "title": "",
              "type": "object",
              "properties": {
                "error": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              },
              "required": [
                "error",
                "message"
              ]
            }
          }
        }
      }
    }
  },
  "paths": {
    "/api/public/v1/servers": {
      "get": {
        "summary": "List Available WireGuard Servers & Regions",
        "description": "Returns offered TunnelSats gateways with their exact domain and geographic metadata. Discovery currently reports static online status; switch invoice creation verifies live gateway availability. Rate limit: 60 requests/min per IP.",
        "tags": [
          "📡 Discovery"
        ],
        "x-apidog-folder": "📡 Discovery",
        "parameters": [
          {
            "name": "Accept",
            "in": "header",
            "required": false,
            "description": "Expected response media type.",
            "schema": {
              "type": "string",
              "default": "application/json",
              "example": "application/json"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of available servers",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "servers": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Server"
                      }
                    }
                  }
                },
                "example": {
                  "servers": [
                    {
                      "id": "eu-de",
                      "country": "Germany",
                      "city": "Nuremberg",
                      "flag": "🇩🇪",
                      "status": "online",
                      "domain": "de2.tunnelsats.com"
                    },
                    {
                      "id": "us-east",
                      "country": "USA",
                      "city": "Ashburn",
                      "flag": "🇺🇸",
                      "status": "online",
                      "domain": "us3.tunnelsats.com"
                    },
                    {
                      "id": "us-west",
                      "country": "USA",
                      "city": "Hillsboro",
                      "flag": "🇺🇸",
                      "status": "online",
                      "domain": "us2.tunnelsats.com"
                    },
                    {
                      "id": "asia-sg",
                      "country": "Singapore",
                      "city": "Singapore",
                      "flag": "🇸🇬",
                      "status": "online",
                      "domain": "sg1.tunnelsats.com"
                    },
                    {
                      "id": "sa-br",
                      "country": "Brazil",
                      "city": "Sao Paulo",
                      "flag": "🇧🇷",
                      "status": "online",
                      "domain": "br1.tunnelsats.com"
                    },
                    {
                      "id": "oc-au",
                      "country": "Australia",
                      "city": "Sydney",
                      "flag": "🇦🇺",
                      "status": "online",
                      "domain": "au1.tunnelsats.com"
                    },
                    {
                      "id": "eu-ch",
                      "country": "Switzerland",
                      "city": "Geneva",
                      "flag": "🇨🇭",
                      "status": "online",
                      "domain": "ch1.tunnelsats.com"
                    }
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    },
    "/api/public/v1/subscription/create": {
      "post": {
        "summary": "Create a New WireGuard Subscription (Invoice Generation)",
        "description": "Generates a Lightning invoice to purchase a 1, 3, 6, or 12-month WireGuard VPN tunnel in a chosen region. Rate limit: 10 requests/min per IP.",
        "tags": [
          "⚡ Purchase"
        ],
        "x-apidog-folder": "⚡ Purchase",
        "parameters": [
          {
            "name": "Content-Type",
            "in": "header",
            "required": true,
            "description": "Media type of the request payload. Must be application/json.",
            "schema": {
              "type": "string",
              "default": "application/json",
              "example": "application/json"
            }
          },
          {
            "name": "Accept",
            "in": "header",
            "required": false,
            "description": "Expected response media type.",
            "schema": {
              "type": "string",
              "default": "application/json",
              "example": "application/json"
            }
          },
          {
            "name": "Authorization",
            "in": "header",
            "required": false,
            "description": "Optional. Links purchase to your account for dashboard tracking. Bearer sk_live_... or Nostr <base64-event>.",
            "schema": {
              "type": "string",
              "example": "Bearer sk_live_a1b2c3d4e5f6g7h8i9j0"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "serverId",
                  "duration"
                ],
                "properties": {
                  "serverId": {
                    "type": "string",
                    "description": "Target server identifier (e.g. eu-de, us-east).",
                    "example": "eu-de"
                  },
                  "duration": {
                    "type": "integer",
                    "enum": [
                      1,
                      3,
                      6,
                      12
                    ],
                    "description": "Subscription duration in months.",
                    "example": 1
                  },
                  "referralCode": {
                    "type": "string",
                    "nullable": true,
                    "description": "Optional partner referral code (e.g. REF-ABC123). Must be an existing code: unknown codes, and your own code when you are authenticated, are rejected with 400 before an invoice is created (anonymous requests carry no account identity to check for self-referral). When a 3, 6 or 12-month order with a valid non-self-referral code is paid, both the new subscription and the code owner receive +1, +2 or +3 bonus months (the code owner is credited exactly once), whichever path settles the order (payment webhook, status polling or /claim).",
                    "example": null
                  },
                  "wgPublicKey": {
                    "type": "string",
                    "description": "Optional but recommended. Omit the field rather than sending null. Your WireGuard public key (44-char Base64). When set, every provisioning path (payment webhook, status polling, /claim) uses this key only: the server never generates or stores a private key for the order, and /claim must be called with the same key.",
                    "example": "hnG/fWsNx7DiVbGUj3B/i0EtXvpIZdO5cuoQJCTWhRU="
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lightning invoice generated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InvoiceOrder"
                },
                "example": {
                  "invoice": "lnbc41130n1p5a4p2dpp5pwd0d2ua837kz...",
                  "paymentHash": "0b9af6ab9d3c7d6146e3f28ca11bf4b830f4cab95330c5a5c9b25b7827afc44c",
                  "amountSats": 4113,
                  "orderId": "ab897fc4-41ff-4a55-9bb6-0ce1623e7a87"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input (bad serverId or duration, unknown referralCode or self-referral, or invalid wgPublicKey)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    },
    "/api/public/v1/subscription/{paymentHash}": {
      "get": {
        "summary": "Check Invoice Status & Polling by Payment Hash",
        "description": "Poll this endpoint after payment to check invoice settlement status. Returns subscription details once paid. Also accepts bandwidth-reset payment hashes: those return a BandwidthResetPaymentStatus (type \"bandwidth_reset\"), and a paid reset whose webhook was missed is applied on the poll. Rate limit: 60 requests/min per IP. Region-switch hashes return RegionSwitchPaymentStatus (type region_switch) and use a separate rolling 30 requests/min per trusted client IP. Missed webhooks are healed using verified LNBits settlement; paid means committed provisioning, not payment alone. Provider uncertainty returns 503 without inventing unpaid/expired state. Processing returns 202. Terminal failures retain quota for operator recovery. No PSK, private key, or full config is returned.",
        "tags": [
          "⚡ Purchase"
        ],
        "x-apidog-folder": "⚡ Purchase",
        "parameters": [
          {
            "name": "paymentHash",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Payment hash of the invoice (64-character hex string)."
          },
          {
            "name": "Accept",
            "in": "header",
            "required": false,
            "description": "Expected response media type.",
            "schema": {
              "type": "string",
              "default": "application/json",
              "example": "application/json"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Subscription/Invoice status",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/SubscriptionStatus"
                    },
                    {
                      "$ref": "#/components/schemas/BandwidthResetPaymentStatus"
                    },
                    {
                      "$ref": "#/components/schemas/RegionSwitchPaymentStatus"
                    }
                  ]
                },
                "examples": {
                  "subscription": {
                    "summary": "Subscription order",
                    "value": {
                      "status": "paid",
                      "subscriptionEnd": "2026-10-15T12:00:00Z",
                      "bandwidthUsed": 0,
                      "server": {
                        "id": "eu-de",
                        "domain": "de2.tunnelsats.com",
                        "endpoint": "de2.tunnelsats.com:51820"
                      }
                    }
                  },
                  "bandwidthReset": {
                    "summary": "Bandwidth reset applied",
                    "value": {
                      "paymentHash": "c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4",
                      "type": "bandwidth_reset",
                      "status": "paid",
                      "resetId": "d7b2277f-5990-4721-a565-6816babadc59",
                      "expiresAt": "2026-09-27T11:00:00.000Z",
                      "message": "Bandwidth reset applied."
                    }
                  },
                  "regionSwitch": {
                    "summary": "Region switch provisioned",
                    "value": {
                      "type": "region_switch",
                      "paymentHash": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
                      "migrationId": "41300000-0000-4000-8000-000000000001",
                      "expiresAt": "2026-11-02T12:15:00.000Z",
                      "status": "paid",
                      "isProvisioned": true,
                      "retryable": false
                    }
                  }
                }
              }
            }
          },
          "202": {
            "description": "Paid; the subscription is being provisioned, the renewal or the bandwidth reset is being applied. Poll again. Region switches use the same provisioning-in-progress semantics.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "paymentHash": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "processing"
                      ]
                    },
                    "message": {
                      "type": "string"
                    },
                    "type": {
                      "type": "string",
                      "enum": [
                        "region_switch"
                      ]
                    },
                    "migrationId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "expiresAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "isProvisioned": {
                      "type": "boolean"
                    },
                    "retryable": {
                      "type": "boolean"
                    },
                    "reason": {
                      "type": "string"
                    },
                    "operatorActionRequired": {
                      "type": "boolean"
                    }
                  }
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer",
                  "minimum": 1
                },
                "description": "Seconds before retrying a rate-limited, processing, or unavailable request."
              }
            }
          },
          "404": {
            "description": "Subscription not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "429": {
            "description": "IP/proof rate limit or shared monthly quota exhausted.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              },
              "Retry-After": {
                "schema": {
                  "type": "integer",
                  "minimum": 1
                },
                "description": "Seconds before retrying a rate-limited, processing, or unavailable request."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "503": {
            "description": "Payment state could not be verified right now (e.g. the Lightning backend is unreachable). Retry later; never treat as unpaid.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    },
    "/api/public/v1/subscription/claim": {
      "post": {
        "summary": "Claim WireGuard Configuration After Payment Settlement",
        "description": "Provisions or retrieves the WireGuard configuration once the Lightning invoice payment has settled. For orders created with a wgPublicKey, send the same wgPublicKey here; the response then contains only the tunnel parameters (server, peer, vpnPort) and never a config or private key. Rate limit: 10 requests/min per IP.",
        "tags": [
          "⚡ Purchase"
        ],
        "x-apidog-folder": "⚡ Purchase",
        "parameters": [
          {
            "name": "Content-Type",
            "in": "header",
            "required": true,
            "description": "Media type of the request payload. Must be application/json.",
            "schema": {
              "type": "string",
              "default": "application/json",
              "example": "application/json"
            }
          },
          {
            "name": "Accept",
            "in": "header",
            "required": false,
            "description": "Expected response media type.",
            "schema": {
              "type": "string",
              "default": "application/json",
              "example": "application/json"
            }
          },
          {
            "name": "Authorization",
            "in": "header",
            "required": false,
            "description": "Optional. Links this subscription to your account. Bearer sk_live_... or Nostr <base64-event>.",
            "schema": {
              "type": "string",
              "example": "Bearer sk_live_a1b2c3d4e5f6g7h8i9j0"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "paymentHash"
                ],
                "properties": {
                  "paymentHash": {
                    "type": "string",
                    "description": "Payment hash from the /create response.",
                    "example": "0b9af6ab9d3c7d6146e3f28ca11bf4b830f4cab95330c5a5c9b25b7827afc44c"
                  },
                  "wgPublicKey": {
                    "type": "string",
                    "description": "Your WireGuard public key (44-char Base64). Required, and must match, if the order was created with a wgPublicKey. Otherwise optional; if omitted, keys are generated server-side. Omit the field rather than sending null.",
                    "example": "hnG/fWsNx7DiVbGUj3B/i0EtXvpIZdO5cuoQJCTWhRU="
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "WireGuard configuration provisioned",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ClaimResult"
                }
              }
            }
          },
          "202": {
            "description": "Payment confirmed, provisioning in progress (client-held key orders). Retry the claim.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "paymentHash": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string",
                      "example": "processing"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "402": {
            "description": "Invoice not yet paid",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "404": {
            "description": "Subscription not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "409": {
            "description": "wgPublicKey missing or different from the key registered at /create",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    },
    "/api/public/v1/subscription/status": {
      "post": {
        "summary": "Get Subscription & Bandwidth Status by WireGuard Public Key",
        "description": "Polls WireGuard servers to return real-time expiry, bandwidth consumption and quota, bandwidth-reset allowance, peer status, hosting server domain and forwarded port. No authentication required. Rate limit: 30 requests/min per IP.\n\n**404 vs 503:** 404 means every VPN server answered and none holds the key: the key is unknown (import or buy a subscription). 503 (`ERR_SERVICE_UNAVAILABLE`, with `Retry-After`) means the key was not found on the servers that answered but at least one server could not be checked: retry later and do not treat the key as unknown. When an active server cannot be checked, a copy of the key on a legacy server is not reported either (the active server may hold the current one), so that case is a 503 as well.\n\n**Migrated source keys:** committed region switches return HTTP 200 with `status: \"disabled\"`, `migrated_to_server_domain` and `grace_expires_at`, using the local switch journal before any gateway or payment-provider lookup. This survives source deletion, gateway outages, and committed cleanup failures. Suppress 7-day/1-day expiry and 70%-bandwidth reminders for these keys, and ask users to `/link` their new public key. Other response fields are historical source snapshots (see schema), `vpn_port` is null, and monthly quota counts locally retained lineage slots. An ancestor points to its own immediate switch destination, even after successive switches. Pre-commit failures do not trigger this suppression. Unknown/unmigrated keys retain the 404/503 behavior above.",
        "tags": [
          "🔄 Lifecycle"
        ],
        "x-apidog-folder": "🔄 Lifecycle",
        "parameters": [
          {
            "name": "Content-Type",
            "in": "header",
            "required": true,
            "description": "Media type of the request payload. Must be application/json.",
            "schema": {
              "type": "string",
              "default": "application/json",
              "example": "application/json"
            }
          },
          {
            "name": "Accept",
            "in": "header",
            "required": false,
            "description": "Expected response media type.",
            "schema": {
              "type": "string",
              "default": "application/json",
              "example": "application/json"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "wgPublicKey"
                ],
                "properties": {
                  "wgPublicKey": {
                    "type": "string",
                    "description": "WireGuard public key (44-character Base64 string).",
                    "example": "pWyZTQx8C4gzzgMVJHiN1ptI46wDtyJSMRa+wxtkXOM="
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Subscription status and bandwidth data",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PublicKeyStatusResponse"
                },
                "example": {
                  "expiry": "2026-10-15T12:00:00Z",
                  "bandwidth_used_gb": 45.67,
                  "bandwidth_limit_gb": 100,
                  "bandwidth_resets_this_month": 0,
                  "max_resets_per_month": 2,
                  "status": "enabled",
                  "server_domain": "de2.tunnelsats.com",
                  "vpn_port": 24556,
                  "last_synced_at": "2026-09-01T12:00:00Z"
                }
              }
            }
          },
          "404": {
            "description": "Every VPN server answered and none holds the key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "503": {
            "description": "Key not found on the servers that answered, but at least one server could not be checked. Retryable; the key is not known to be absent.",
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before retrying.",
                "schema": {
                  "type": "integer",
                  "example": 30
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                },
                "example": {
                  "error": "ERR_SERVICE_UNAVAILABLE",
                  "message": "Subscription status is temporarily unavailable: not every VPN server could be checked. Please retry."
                }
              }
            }
          }
        }
      }
    },
    "/api/public/v1/subscription/renew": {
      "post": {
        "summary": "Renew an Existing VPN Subscription (Anonymous)",
        "description": "Generates a Lightning renewal invoice for an existing WireGuard public key on a target server. No authentication required. Rate limit: 20 requests/min per IP.",
        "tags": [
          "🔄 Lifecycle"
        ],
        "x-apidog-folder": "🔄 Lifecycle",
        "parameters": [
          {
            "name": "Content-Type",
            "in": "header",
            "required": true,
            "description": "Media type of the request payload. Must be application/json.",
            "schema": {
              "type": "string",
              "default": "application/json",
              "example": "application/json"
            }
          },
          {
            "name": "Accept",
            "in": "header",
            "required": false,
            "description": "Expected response media type.",
            "schema": {
              "type": "string",
              "default": "application/json",
              "example": "application/json"
            }
          },
          {
            "name": "Authorization",
            "in": "header",
            "required": false,
            "description": "Optional. Links renewal to your account. Bearer sk_live_... or Nostr <base64-event>.",
            "schema": {
              "type": "string",
              "example": "Bearer sk_live_a1b2c3d4e5f6g7h8i9j0"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "wgPublicKey",
                  "serverId",
                  "duration"
                ],
                "properties": {
                  "wgPublicKey": {
                    "type": "string",
                    "description": "WireGuard public key to renew (44-character Base64).",
                    "example": "pWyZTQx8C4gzzgMVJHiN1ptI46wDtyJSMRa+wxtkXOM="
                  },
                  "serverId": {
                    "type": "string",
                    "description": "Server where the subscription is hosted.",
                    "example": "eu-de"
                  },
                  "duration": {
                    "type": "integer",
                    "enum": [
                      1,
                      3,
                      6,
                      12
                    ],
                    "description": "Renewal duration in months.",
                    "example": 3
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Renewal invoice generated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RenewalOrder"
                },
                "example": {
                  "invoice": "lnbc30000n1p...",
                  "paymentHash": "b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3",
                  "oldExpiry": "2026-09-15T12:00:00Z",
                  "newExpiry": "2026-12-15T12:00:00Z",
                  "renewalId": "f47ac10b-58cc-4372-a567-0e02b2c3d479"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "404": {
            "description": "Subscription not found on target server (every server of the target group answered)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "409": {
            "description": "Retired region-switch source peer (`ERR_PAYMENT_FAILED`). Renew the active destination WireGuard public key instead.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                },
                "example": {
                  "error": "ERR_PAYMENT_FAILED",
                  "message": "This peer was replaced by a region switch. Renew the active destination key instead."
                }
              }
            }
          },
          "503": {
            "description": "Retryable. `ERR_SERVICE_UNAVAILABLE` (with `Retry-After`): a server of the target group, or the legacy server us1 checked by the us3 migration guard, could not be reached, so the key could be neither found nor ruled out. Also returned as `ERR_INTERNAL_ERROR` while maintenance mode disables renewals.",
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before retrying.",
                "schema": {
                  "type": "integer",
                  "example": 30
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                },
                "example": {
                  "error": "ERR_SERVICE_UNAVAILABLE",
                  "message": "Could not reach the VPN server to verify this subscription. Please retry."
                }
              }
            }
          }
        }
      }
    },
    "/api/public/v1/subscription/{paymentHash}/sync": {
      "post": {
        "summary": "Sync Subscription (Real-Time Server Refresh)",
        "description": "Triggers a real-time sync from the VPN server to refresh bandwidth, expiry, and peer status. Requires authentication and subscription ownership. Rate limit: 5 requests/min per subscription.",
        "tags": [
          "🔄 Lifecycle"
        ],
        "x-apidog-folder": "🔄 Lifecycle",
        "security": [
          {
            "ApiKeyAuth": []
          },
          {
            "NostrAuth": []
          }
        ],
        "parameters": [
          {
            "name": "paymentHash",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Payment hash or order ID of the subscription to sync."
          },
          {
            "name": "Authorization",
            "in": "header",
            "required": true,
            "description": "TunnelSats API Key (Bearer sk_live_...) or NIP-98 Nostr auth (Nostr <base64-event>).",
            "schema": {
              "type": "string",
              "example": "Bearer sk_live_a1b2c3d4e5f6g7h8i9j0"
            }
          },
          {
            "name": "Accept",
            "in": "header",
            "required": false,
            "description": "Expected response media type.",
            "schema": {
              "type": "string",
              "default": "application/json",
              "example": "application/json"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Subscription synced successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SyncResult"
                },
                "example": {
                  "success": true,
                  "subscription": {
                    "expiry": "2026-10-15T12:00:00Z",
                    "bandwidth_used_gb": 45.67,
                    "status": "enabled",
                    "server_domain": "de2.tunnelsats.com"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized (missing or invalid auth token)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "404": {
            "description": "Subscription not found or not owned by authenticated user",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (max 5 syncs/min per subscription)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    },
    "/api/public/v1/subscription/bandwidth-reset": {
      "post": {
        "summary": "Request Bandwidth Top-Up ($1 Usage Reset)",
        "description": "Generates a $1 USD Lightning invoice for a bandwidth reset. Once it is paid, the key's usage counter for the current month goes back to 0, so its full allowance is available again; a reset does not add allowance on top, and unused allowance does not carry over. A reset also re-enables a peer that was disabled for exceeding its allowance. There is no usage threshold: a reset is available at any usage while the subscription is active, so automated clients should apply their own usage policy before paying. While an unpaid invoice for the key is still open, a new request returns that same invoice instead of creating another one. Rate limit: 10 requests/min per IP. Monthly limit: 2 paid bandwidth resets and region switches combined per UTC calendar month across the subscription lineage; reservations and invoices hold their slots until consumed or safely released after verified nonpayment.",
        "tags": [
          "🔄 Lifecycle"
        ],
        "x-apidog-folder": "🔄 Lifecycle",
        "parameters": [
          {
            "name": "Content-Type",
            "in": "header",
            "required": true,
            "description": "Media type of the request payload. Must be application/json.",
            "schema": {
              "type": "string",
              "default": "application/json",
              "example": "application/json"
            }
          },
          {
            "name": "Accept",
            "in": "header",
            "required": false,
            "description": "Expected response media type.",
            "schema": {
              "type": "string",
              "default": "application/json",
              "example": "application/json"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "wgPublicKey",
                  "serverId"
                ],
                "properties": {
                  "wgPublicKey": {
                    "type": "string",
                    "description": "WireGuard public key (44-character Base64 string).",
                    "example": "pWyZTQx8C4gzzgMVJHiN1ptI46wDtyJSMRa+wxtkXOM="
                  },
                  "serverId": {
                    "type": "string",
                    "description": "Server identifier, group domain (eu-de, us-east), or full domain (us3.tunnelsats.com).",
                    "example": "us-east"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Bandwidth reset invoice generated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BandwidthResetResponse"
                },
                "example": {
                  "invoice": "lnbc30000n1p...",
                  "paymentHash": "c3d4e5f6a1b2...",
                  "resetId": "d7b2277f-5990-4721-a565-6816babadc59",
                  "amountSats": 3000,
                  "amountUsd": "1.00",
                  "currentUsagePercent": "85.4",
                  "resetsThisMonth": 0,
                  "maxResetsPerMonth": 2,
                  "expiresAt": "2026-09-27T11:00:00.000Z"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input (bad key format, unknown server, expired subscription or missing expiry date)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "403": {
            "description": "Refused before any quota slot or invoice. `ERR_MIGRATION_REQUIRED`: the key is on the legacy server us1, where resets are no longer sold; migrate to us3 first. `ERR_FORBIDDEN`: the key was disabled for a reason other than its bandwidth limit (for example after a migration), so a reset would not restore it; contact support.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                },
                "example": {
                  "error": "ERR_MIGRATION_REQUIRED",
                  "message": "Bandwidth resets on our legacy server (us1) are no longer available. Please use the migration tool to move to us3."
                }
              }
            }
          },
          "404": {
            "description": "Key not found on target server (every server of the target group answered)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "409": {
            "description": "Retired region-switch source peer (`ERR_PAYMENT_FAILED`). Request a bandwidth reset on the active destination WireGuard public key instead.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                },
                "example": {
                  "error": "ERR_PAYMENT_FAILED",
                  "message": "This peer was replaced by a region switch. Reset bandwidth on the active destination key instead."
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded or monthly reset limit reached (max 2/month per key)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "503": {
            "description": "Retryable. `ERR_SERVICE_UNAVAILABLE` (with `Retry-After`): a server of the target group could not be reached, the key's subscription could not be read, or the state of a disabled key could not be verified. Also returned as `ERR_INTERNAL_ERROR` while maintenance mode disables resets.",
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before retrying.",
                "schema": {
                  "type": "integer",
                  "example": 30
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                },
                "example": {
                  "error": "ERR_SERVICE_UNAVAILABLE",
                  "message": "Could not reach the VPN server to verify this subscription. Please retry."
                }
              }
            }
          }
        }
      }
    },
    "/api/public/v1/subscription/list": {
      "get": {
        "summary": "List Account Subscriptions (Authenticated)",
        "description": "Returns all subscriptions linked to your authenticated account. Note: response uses snake_case keys (e.g. payment_hash, subscription_end). Rate limit: 30 requests/min per account.",
        "tags": [
          "🔑 Account"
        ],
        "x-apidog-folder": "🔑 Account",
        "security": [
          {
            "ApiKeyAuth": []
          },
          {
            "NostrAuth": []
          }
        ],
        "parameters": [
          {
            "name": "Authorization",
            "in": "header",
            "required": true,
            "description": "TunnelSats API Key (Bearer sk_live_...) or NIP-98 Nostr auth (Nostr <base64-event>).",
            "schema": {
              "type": "string",
              "example": "Bearer sk_live_a1b2c3d4e5f6g7h8i9j0"
            }
          },
          {
            "name": "Accept",
            "in": "header",
            "required": false,
            "description": "Expected response media type.",
            "schema": {
              "type": "string",
              "default": "application/json",
              "example": "application/json"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of active subscriptions",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "subscriptions": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/SubscriptionListItem"
                      }
                    }
                  }
                },
                "example": {
                  "subscriptions": [
                    {
                      "payment_hash": "a1b2c3d4e5f6...",
                      "server_domain": "de2.tunnelsats.com",
                      "subscription_end": "2026-10-15T12:00:00Z",
                      "status": "paid",
                      "bandwidth_used_gb": 12.5
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized (Missing or invalid Bearer/Nostr token)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    },
    "/api/referral/create": {
      "post": {
        "summary": "Create Referral Code",
        "description": "Returns the referral code of your authenticated account and creates it on the first call. The call is idempotent: repeated calls return the same code. Share it as `https://tunnelsats.com?ref=<code>` or pass it as `referralCode` to `POST /api/public/v1/subscription/create`. Each referred 3, 6 or 12-month purchase credits you +1, +2 or +3 bonus months once, when it is paid (listed by `GET /api/referral/history`). No request body. Rate limit: 30 requests/min per account.",
        "tags": [
          "🔑 Account"
        ],
        "x-apidog-folder": "🔑 Account",
        "security": [
          {
            "ApiKeyAuth": []
          },
          {
            "NostrAuth": []
          }
        ],
        "parameters": [
          {
            "name": "Authorization",
            "in": "header",
            "required": true,
            "description": "TunnelSats API Key (Bearer sk_live_...) or NIP-98 Nostr auth (Nostr <base64-event>).",
            "schema": {
              "type": "string",
              "example": "Bearer sk_live_a1b2c3d4e5f6g7h8i9j0"
            }
          },
          {
            "name": "Accept",
            "in": "header",
            "required": false,
            "description": "Expected response media type.",
            "schema": {
              "type": "string",
              "default": "application/json",
              "example": "application/json"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Your referral code (newly created or existing)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReferralCode"
                },
                "example": {
                  "code": "REF-7K2Q9Z",
                  "created_at": "2026-01-15 09:30:00",
                  "usage_count": 3
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized (missing or invalid Bearer/Nostr token)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                },
                "example": {
                  "error": "ERR_UNAUTHORIZED",
                  "message": "Missing Authorization header"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (max 30 requests/min per account for this endpoint)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                },
                "example": {
                  "error": "ERR_RATE_LIMIT_EXCEEDED",
                  "message": "Rate limit exceeded"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                },
                "example": {
                  "error": "ERR_INTERNAL_ERROR",
                  "message": "Internal Server Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "summary": "Get Referral Code",
        "description": "Returns the referral code of your authenticated account, or `null` if you have not created one yet (use `POST /api/referral/create`). Rate limit: 30 requests/min per account, separate from the POST budget.",
        "tags": [
          "🔑 Account"
        ],
        "x-apidog-folder": "🔑 Account",
        "security": [
          {
            "ApiKeyAuth": []
          },
          {
            "NostrAuth": []
          }
        ],
        "parameters": [
          {
            "name": "Authorization",
            "in": "header",
            "required": true,
            "description": "TunnelSats API Key (Bearer sk_live_...) or NIP-98 Nostr auth (Nostr <base64-event>).",
            "schema": {
              "type": "string",
              "example": "Bearer sk_live_a1b2c3d4e5f6g7h8i9j0"
            }
          },
          {
            "name": "Accept",
            "in": "header",
            "required": false,
            "description": "Expected response media type.",
            "schema": {
              "type": "string",
              "default": "application/json",
              "example": "application/json"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Your referral code, or null if none exists yet",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "nullable": true,
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ReferralCode"
                    }
                  ]
                },
                "example": {
                  "code": "REF-7K2Q9Z",
                  "created_at": "2026-01-15 09:30:00",
                  "usage_count": 3
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized (missing or invalid Bearer/Nostr token)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                },
                "example": {
                  "error": "ERR_UNAUTHORIZED",
                  "message": "Missing Authorization header"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (max 30 requests/min per account for this endpoint)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                },
                "example": {
                  "error": "ERR_RATE_LIMIT_EXCEEDED",
                  "message": "Rate limit exceeded"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                },
                "example": {
                  "error": "ERR_INTERNAL_ERROR",
                  "message": "Internal Server Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/referral/history": {
      "get": {
        "summary": "Referral History",
        "description": "Lists up to 50 paid or claimed subscriptions that used your referral code, newest first. `bonus_earned` is the number of bonus months the referral qualifies for based on the purchased duration (1 → 0, 3 → 1, 6 → 2, 12 → 3), `bonus_status` reports the credit outcome (`credited`, `pending`, `forfeited`, `skipped`, `legacy`, or `failed`), and `bonus_reason` explains `forfeited` (`no_active_subscription`) or `skipped` (`self_referral`, `not_eligible`) entries. Returns an empty list if you have no code yet. Rate limit: 30 requests/min per account.",
        "tags": [
          "🔑 Account"
        ],
        "x-apidog-folder": "🔑 Account",
        "security": [
          {
            "ApiKeyAuth": []
          },
          {
            "NostrAuth": []
          }
        ],
        "parameters": [
          {
            "name": "Authorization",
            "in": "header",
            "required": true,
            "description": "TunnelSats API Key (Bearer sk_live_...) or NIP-98 Nostr auth (Nostr <base64-event>).",
            "schema": {
              "type": "string",
              "example": "Bearer sk_live_a1b2c3d4e5f6g7h8i9j0"
            }
          },
          {
            "name": "Accept",
            "in": "header",
            "required": false,
            "description": "Expected response media type.",
            "schema": {
              "type": "string",
              "default": "application/json",
              "example": "application/json"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Referral history",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReferralHistory"
                },
                "example": {
                  "history": [
                    {
                      "date": "2026-01-01 19:40:00",
                      "duration_purchased": 3,
                      "bonus_earned": 1,
                      "bonus_status": "credited"
                    },
                    {
                      "date": "2025-12-25 10:00:00",
                      "duration_purchased": 12,
                      "bonus_earned": 3,
                      "bonus_status": "forfeited",
                      "bonus_reason": "no_active_subscription"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized (missing or invalid Bearer/Nostr token)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                },
                "example": {
                  "error": "ERR_UNAUTHORIZED",
                  "message": "Missing Authorization header"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (max 30 requests/min per account for this endpoint)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                },
                "example": {
                  "error": "ERR_RATE_LIMIT_EXCEEDED",
                  "message": "Rate limit exceeded"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                },
                "example": {
                  "error": "ERR_INTERNAL_ERROR",
                  "message": "Internal Server Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/public/v1/ping/lookup": {
      "post": {
        "summary": "Lightning Node Network Address Discovery",
        "description": "Discovers publicly announced network addresses for a Lightning node by its public key. Rate limit: 5 requests/min per IP.",
        "tags": [
          "🔧 Tools"
        ],
        "x-apidog-folder": "🔧 Tools",
        "parameters": [
          {
            "name": "Content-Type",
            "in": "header",
            "required": true,
            "description": "Media type of the request payload. Must be application/json.",
            "schema": {
              "type": "string",
              "default": "application/json",
              "example": "application/json"
            }
          },
          {
            "name": "Accept",
            "in": "header",
            "required": false,
            "description": "Expected response media type.",
            "schema": {
              "type": "string",
              "default": "application/json",
              "example": "application/json"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "pubkey"
                ],
                "properties": {
                  "pubkey": {
                    "type": "string",
                    "description": "Lightning node public key (66-character hex).",
                    "example": "02778f4a4eb3a2344b9fd8ee72e7ec5f03f803e5f5273e737e1c1b106f4b3a5e77"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Discovered addresses",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NodeLookup"
                },
                "example": {
                  "addresses": [
                    "203.0.113.42:9735",
                    "[2001:db8::1]:9735"
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    },
    "/api/public/v1/ping/test": {
      "post": {
        "summary": "Universal Connectivity & Latency Probe",
        "description": "Tests TCP connectivity and measures latency to a Lightning node socket address. Rate limit: 3 requests/min per IP.",
        "tags": [
          "🔧 Tools"
        ],
        "x-apidog-folder": "🔧 Tools",
        "parameters": [
          {
            "name": "Content-Type",
            "in": "header",
            "required": true,
            "description": "Media type of the request payload. Must be application/json.",
            "schema": {
              "type": "string",
              "default": "application/json",
              "example": "application/json"
            }
          },
          {
            "name": "Accept",
            "in": "header",
            "required": false,
            "description": "Expected response media type.",
            "schema": {
              "type": "string",
              "default": "application/json",
              "example": "application/json"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "socket"
                ],
                "properties": {
                  "socket": {
                    "type": "string",
                    "description": "Lightning node socket address in pubkey@host:port format.",
                    "example": "02778f4a4eb3a2344b9fd8ee72e7ec5f03f803e5f5273e737e1c1b106f4b3a5e77@203.0.113.42:9735"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Probe results",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConnectivityResult"
                },
                "example": {
                  "success": true,
                  "reachable": true,
                  "latencyMs": 35,
                  "message": "Connection successful"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1": {
      "get": {
        "summary": "L402 Agent Payment Gateway Discovery Metadata",
        "description": "Safe read-only discovery endpoint describing the POST /api/v1 L402 purchase and redemption flow and linking /openapi.json. Does not emit a fake WWW-Authenticate: L402 challenge or placeholder BOLT11 invoice.",
        "tags": [
          "📡 Discovery"
        ],
        "responses": {
          "200": {
            "description": "L402 Agent Payment Gateway discovery metadata and step-by-step instructions",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "service": {
                      "type": "string",
                      "example": "TunnelSats L402 & x402 Agent Payment Gateway"
                    },
                    "protocol": {
                      "type": "string",
                      "example": "L402"
                    },
                    "endpoint": {
                      "type": "string",
                      "example": "https://tunnelsats.com/api/v1"
                    },
                    "method": {
                      "type": "string",
                      "example": "POST"
                    },
                    "openapiUrl": {
                      "type": "string",
                      "example": "https://tunnelsats.com/openapi.json"
                    },
                    "instructions": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        },
        "x-apidog-folder": "📡 Discovery"
      },
      "post": {
        "summary": "Autonomous Agent HTTP 402 Gateway (L402 Purchase + Claim)",
        "description": "Unified HTTP 402 endpoint for autonomous AI agents. When called without Authorization: L402 <macaroon>:<preimage> (or X-PAYMENT), creates a BOLT11 Lightning invoice and pending order and returns HTTP 402 Payment Required with a binary V2 L402 macaroon. When replayed with Authorization: L402 <macaroon>:<preimage>, cryptographically verifies the V2 macaroon and SHA256(preimage) == paymentHash, confirms settlement, and returns 200 OK with the provisioned WireGuard tunnel parameters.",
        "x-l402-payment-info": {
          "scheme": "L402",
          "intent": "charge",
          "method": "lightning",
          "amount": null,
          "currency": "sat",
          "description": "USD-pegged price; the exact integer satoshi amount is returned in the live HTTP 402 L402 challenge."
        },
        "tags": [
          "⚡ Purchase"
        ],
        "security": [
          {},
          {
            "L402Auth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "serverId": {
                    "type": "string",
                    "description": "Target server identifier (e.g. eu-de, us-east) for initial 402 challenge creation.",
                    "example": "eu-de"
                  },
                  "duration": {
                    "type": "integer",
                    "enum": [
                      1,
                      3,
                      6,
                      12
                    ],
                    "description": "Subscription duration in months.",
                    "example": 1
                  },
                  "wgPublicKey": {
                    "type": "string",
                    "description": "Client-held WireGuard public key (44-char Base64).",
                    "example": "hnG/fWsNx7DiVbGUj3B/i0EtXvpIZdO5cuoQJCTWhRU="
                  },
                  "referralCode": {
                    "type": "string",
                    "nullable": true,
                    "description": "Optional partner referral code.",
                    "example": null
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "WireGuard tunnel provisioned after L402 preimage verification",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ClaimResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input (unknown serverId, invalid duration, invalid wgPublicKey, unknown or self-referred referralCode, or L402 request body caveat mismatch)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "401": {
            "description": "Invalid or expired L402 macaroon or Lightning payment preimage",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "402": {
            "description": "HTTP 402 Payment Required challenge with live BOLT11 invoice and signed L402 macaroon",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "wgPublicKey mismatch against the key bound in the L402 macaroon or order",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        },
        "x-apidog-folder": "⚡ Purchase"
      }
    },
    "/api/public/v1/subscription/migrate/check": {
      "post": {
        "summary": "Check Region Switch Eligibility",
        "description": "Locate the current key across offered gateways (and test gateways only when enabled). serverId optionally selects the source gateway ID. Requires strictly more than 24 hours remaining. Returns shared 2/UTC-month quota and 72-hour/2000 MB grace rules. Eligible sources receive a durable ten-minute X25519 challenge. Quota-exhausted sources may also receive a challenge to recover an exact existing unpaid invoice; the challenge reserves no slot. Expired invoices release quota only after authoritative unpaid confirmation. Rate limit: 10 requests/min per IP (rolling window). Request bodies are limited to 8192 bytes.",
        "tags": [
          "🔄 Lifecycle"
        ],
        "x-apidog-folder": "🔄 Lifecycle",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "wgPublicKey"
                ],
                "properties": {
                  "wgPublicKey": {
                    "type": "string",
                    "minLength": 44,
                    "maxLength": 44,
                    "pattern": "^[A-Za-z0-9+/]{43}=$",
                    "description": "Canonical 32-byte X25519 WireGuard public key; weak/low-order points are rejected."
                  },
                  "serverId": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64
                  }
                },
                "additionalProperties": false
              },
              "example": {
                "wgPublicKey": "hSDwCYkwp1R0i33ctD73Wg2/Og0mOBr066SpjqqbTmo=",
                "serverId": "eu-de"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Advisory eligibility, quota, and optional ownership challenge.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RegionSwitchCheckResult"
                },
                "example": {
                  "eligible": true,
                  "reason": null,
                  "currentServer": {
                    "id": "eu-de",
                    "domain": "de2.tunnelsats.com",
                    "country": "Germany",
                    "city": "Nuremberg",
                    "flag": "🇩🇪"
                  },
                  "subscriptionEnd": "2027-03-01T12:34:56.000Z",
                  "resetsThisMonth": 0,
                  "maxResetsPerMonth": 2,
                  "remainingSlots": 2,
                  "grace": {
                    "maxHours": 72,
                    "additionalMb": 2000,
                    "cappedAtSourceAllowance": true,
                    "unlimited": false
                  },
                  "challengePubKey": "V4TFx8LMrIYdUKJeXVi7/H5CYHrWE1UlX6WTxD063wY=",
                  "challengeWindow": 123,
                  "challengeExpiresAt": "2026-11-02T12:10:00.000Z"
                }
              }
            }
          },
          "400": {
            "description": "Malformed or ineligible request.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "403": {
            "description": "Wrong owner or invalid ownership proof.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "404": {
            "description": "Source or migration not found.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "409": {
            "description": "Expired challenge, conflicting request, mismatched key, unsupported Web mode, or superseded source/destination.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "413": {
            "description": "Request body exceeds 8192 bytes.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "429": {
            "description": "IP/proof rate limit or shared monthly quota exhausted.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              },
              "Retry-After": {
                "schema": {
                  "type": "integer",
                  "minimum": 1
                },
                "description": "Seconds before retrying a rate-limited, processing, or unavailable request."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "500": {
            "description": "Non-retryable switch failure; may require operator recovery.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "503": {
            "description": "Creation disabled/maintenance, configuration failure, busy mutation, or unverifiable provider/gateway state. Never interpret this as unpaid.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              },
              "Retry-After": {
                "schema": {
                  "type": "integer",
                  "minimum": 1
                },
                "description": "Seconds before retrying a rate-limited, processing, or unavailable request."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    },
    "/api/public/v1/subscription/migrate": {
      "post": {
        "summary": "Create or Reuse Region Switch Invoice",
        "description": "Authorize with either source-private-key possession (proof x25519:<base64-shared-secret> against the current check challenge, echoing challengeWindow) or an owning Bearer sk_live_... / Nostr NIP-98 account. Cookie sessions and PSK proofs are not accepted. NIP-98 requires an exact absolute u URL including query, matching method, a timestamp within 60 seconds, and the SHA256 of the exact request body in a payload tag. Invalid supplied account credentials never fall back to a proof. Never transmit either WireGuard private key. The new public key must be fresh and strong. Atomically reserves one shared monthly $1.00 slot before LNBits creation; exact unpaid retries reuse an invoice with more than 30 seconds remaining. Bound proofs cannot change target/key before their ten-minute challenge expires. Invoice lifetime is at most one hour and capped before UTC month rollover. Rate limits: 10 requests/min per IP (rolling), five failed proofs/hour per source public key across IPs. Request bodies are limited to 8192 bytes.",
        "tags": [
          "🔄 Lifecycle"
        ],
        "x-apidog-folder": "🔄 Lifecycle",
        "security": [
          {},
          {
            "ApiKeyAuth": []
          },
          {
            "NostrAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "sourceWgPublicKey",
                  "targetServerId",
                  "newWgPublicKey"
                ],
                "properties": {
                  "sourceWgPublicKey": {
                    "type": "string",
                    "minLength": 44,
                    "maxLength": 44,
                    "pattern": "^[A-Za-z0-9+/]{43}=$",
                    "description": "Canonical 32-byte X25519 WireGuard public key; weak/low-order points are rejected."
                  },
                  "targetServerId": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64
                  },
                  "newWgPublicKey": {
                    "type": "string",
                    "minLength": 44,
                    "maxLength": 44,
                    "pattern": "^[A-Za-z0-9+/]{43}=$",
                    "description": "Canonical 32-byte X25519 WireGuard public key; weak/low-order points are rejected."
                  },
                  "proof": {
                    "type": "string",
                    "maxLength": 128,
                    "description": "Required without account auth; x25519:<32-byte-base64-shared-secret>."
                  },
                  "challengeWindow": {
                    "type": "integer",
                    "minimum": 1,
                    "description": "Required with a proof; use the exact check response identifier."
                  }
                },
                "additionalProperties": false
              },
              "example": {
                "sourceWgPublicKey": "hSDwCYkwp1R0i33ctD73Wg2/Og0mOBr066SpjqqbTmo=",
                "targetServerId": "eu-ch",
                "newWgPublicKey": "3p7bfXt9wbTTW2HC7OQ1Nz+DQ8hbeGdNrfx+FG+IK08=",
                "proof": "x25519:C1qwwR+zCDFSMb3vTSuEVCwmIaLV6r4egeVreJRAv3s=",
                "challengeWindow": 123
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "New or reused $1.00 BOLT11 invoice; resetsThisMonth includes its held slot.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RegionSwitchInvoice"
                },
                "example": {
                  "invoice": "lnbc1example-not-payable",
                  "paymentHash": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
                  "migrationId": "41300000-0000-4000-8000-000000000001",
                  "amountSats": 1000,
                  "amountUsd": "1.00",
                  "expiresAt": "2026-11-02T12:15:00.000Z",
                  "resetsThisMonth": 1,
                  "maxResetsPerMonth": 2
                }
              }
            }
          },
          "400": {
            "description": "Malformed or ineligible request.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid account authentication or ownership credentials.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "403": {
            "description": "Wrong owner or invalid ownership proof.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "404": {
            "description": "Source or migration not found.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "409": {
            "description": "Expired challenge, conflicting request, mismatched key, unsupported Web mode, or superseded source/destination.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "413": {
            "description": "Request body exceeds 8192 bytes.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "429": {
            "description": "IP/proof rate limit or shared monthly quota exhausted.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              },
              "Retry-After": {
                "schema": {
                  "type": "integer",
                  "minimum": 1
                },
                "description": "Seconds before retrying a rate-limited, processing, or unavailable request."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "500": {
            "description": "Non-retryable switch failure; may require operator recovery.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "503": {
            "description": "Creation disabled/maintenance, configuration failure, busy mutation, or unverifiable provider/gateway state. Never interpret this as unpaid.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              },
              "Retry-After": {
                "schema": {
                  "type": "integer",
                  "minimum": 1
                },
                "description": "Seconds before retrying a rate-limited, processing, or unavailable request."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    },
    "/api/public/v1/subscription/migrate/claim": {
      "post": {
        "summary": "Claim Client-Held Region Switch Parameters",
        "description": "Retrieve using paymentHash plus the immutable registered destination wgPublicKey. The pair is a retrieval capability; a public key alone cannot authorize creating a switch. May heal a missed webhook through verified settlement. Returns the client-held purchase-claim shape plus graceExpiresAt, never a private key or full config. Persist these parameters and assemble the config locally. Retries are idempotent and remain available after source-grace cleanup while this destination remains current. Superseded destinations and Web-mode full-config recovery are refused. Creation flags, maintenance, or missing creation-origin configuration do not disable paid recovery. Rate limit: 10 requests/min per IP (rolling). Request bodies are limited to 8192 bytes.",
        "tags": [
          "🔄 Lifecycle"
        ],
        "x-apidog-folder": "🔄 Lifecycle",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "paymentHash",
                  "wgPublicKey"
                ],
                "properties": {
                  "paymentHash": {
                    "type": "string",
                    "minLength": 64,
                    "maxLength": 64,
                    "pattern": "^[a-fA-F0-9]{64}$"
                  },
                  "wgPublicKey": {
                    "type": "string",
                    "minLength": 44,
                    "maxLength": 44,
                    "pattern": "^[A-Za-z0-9+/]{43}=$",
                    "description": "Canonical 32-byte X25519 WireGuard public key; weak/low-order points are rejected."
                  }
                },
                "additionalProperties": false
              },
              "example": {
                "paymentHash": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
                "wgPublicKey": "3p7bfXt9wbTTW2HC7OQ1Nz+DQ8hbeGdNrfx+FG+IK08="
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Provisioned tunnel parameters; PSK is sensitive.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RegionSwitchClaimResult"
                },
                "example": {
                  "status": "already_processed",
                  "subscriptionEnd": "2027-03-01T12:34:56.000Z",
                  "server": {
                    "endpoint": "ch1.tunnelsats.com:51820",
                    "publicKey": "V4TFx8LMrIYdUKJeXVi7/H5CYHrWE1UlX6WTxD063wY=",
                    "allowedIPs": "0.0.0.0/0, ::/0"
                  },
                  "peer": {
                    "address": "10.9.0.20/32",
                    "publicKey": "3p7bfXt9wbTTW2HC7OQ1Nz+DQ8hbeGdNrfx+FG+IK08=",
                    "presharedKey": "OjbKgP5jZR9IQkAB1zf5/ZyENNDKOahdZy6UqDF/vvU="
                  },
                  "vpnPort": 30020,
                  "keyId": "20",
                  "graceExpiresAt": "2026-11-05T12:01:00.000Z",
                  "fullConfig": null
                }
              }
            }
          },
          "202": {
            "description": "Verified payment; provisioning or a related mutation is still in flight. Retry the claim.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              },
              "Retry-After": {
                "schema": {
                  "type": "integer",
                  "minimum": 1
                },
                "description": "Seconds before retrying a rate-limited, processing, or unavailable request."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "paymentHash",
                    "status",
                    "retryable"
                  ],
                  "properties": {
                    "paymentHash": {
                      "type": "string",
                      "minLength": 64,
                      "maxLength": 64,
                      "pattern": "^[a-fA-F0-9]{64}$"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "processing"
                      ]
                    },
                    "retryable": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Malformed or ineligible request.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "402": {
            "description": "Payment is not confirmed.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "404": {
            "description": "Source or migration not found.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "409": {
            "description": "Expired challenge, conflicting request, mismatched key, unsupported Web mode, or superseded source/destination.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "410": {
            "description": "Invoice expired unpaid.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "413": {
            "description": "Request body exceeds 8192 bytes.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "429": {
            "description": "IP/proof rate limit or shared monthly quota exhausted.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              },
              "Retry-After": {
                "schema": {
                  "type": "integer",
                  "minimum": 1
                },
                "description": "Seconds before retrying a rate-limited, processing, or unavailable request."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "500": {
            "description": "Non-retryable switch failure; may require operator recovery.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "503": {
            "description": "Creation disabled/maintenance, configuration failure, busy mutation, or unverifiable provider/gateway state. Never interpret this as unpaid.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "Subscription-specific responses use no-store."
              },
              "Retry-After": {
                "schema": {
                  "type": "integer",
                  "minimum": 1
                },
                "description": "Seconds before retrying a rate-limited, processing, or unavailable request."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    }
  }
}