1. Cookbook
TunnelSats Public Wireguard API
  • Announcements
    • 👋 About our team
    • 💫 What is TunnelSats?
    • 🚀 Introducing the TunnelSats Public API v1
    • 🧩 How the TunnelSats StartOS Package Uses the Public API
    • How TunnelSats Leverages Public APIs for Confined VPN Management
    • 🤖 Autonomous Agent Payments (L402 & x402) & Level 5 Agent-Native Architecture
  • 📡 Discovery
    • List Available WireGuard Servers & Regions
      GET
    • L402 Agent Payment Gateway Discovery Metadata
      GET
  • ⚡ Purchase
    • Create a New WireGuard Subscription (Invoice Generation)
      POST
    • Check Invoice Status & Polling by Payment Hash
      GET
    • Claim WireGuard Configuration After Payment Settlement
      POST
    • Autonomous Agent HTTP 402 Gateway (L402 Purchase + Claim)
      POST
  • 🔄 Lifecycle
    • Get Subscription & Bandwidth Status by WireGuard Public Key
      POST
    • Sync Subscription (Real-Time Server Refresh)
      POST
    • Renew an Existing VPN Subscription (Anonymous)
      POST
    • Request Bandwidth Top-Up ($1 Usage Reset)
      POST
  • 🔑 Account
    • List Account Subscriptions (Authenticated)
      GET
    • Create Referral Code
      POST
    • Get Referral Code
      GET
    • Referral History
      GET
  • 🔧 Tools
    • Lightning Node Network Address Discovery
    • Universal Connectivity & Latency Probe
  • Cookbook
    • 🛠️ Automation & Code Examples
    • 🐚 Bash One-Liners
    • 🚑 Node Health & Upkeep
    • ⚡ Bandwidth Top-Up ($1 Usage Reset)
    • 🛡️ Security & Authentication
    • 🎁 Referral Program: Earn Bonus Months
    • 🛑 Error Codes & Troubleshooting
    • 🤖 Agent Payments: L402 & x402 Protocol
  • Schemas
    • Server
    • InvoiceOrder
    • SubscriptionStatus
    • NodeLookup
    • ConnectivityResult
    • ApiError
    • ClaimResult
    • BandwidthResetResponse
    • PublicKeyStatusResponse
    • SubscriptionListItem
    • ReferralCode
    • ReferralHistory
    • BandwidthResetPaymentStatus
    • RenewalOrder
    • SyncResult
Tunnelsats Github
Tunnelsats Telegram
  1. Cookbook

🛡️ Security & Authentication

TunnelSats provides three primary ways to authenticate and pay for requests. Understanding which one to use depends on whether you are building a centralized backend service, a privacy-first Nostr integration, or an autonomous AI agent.

🔑 1. API Keys (Bearer Token)#

API Keys are the simplest way to authenticate and are recommended for most backend integrators.
Format: sk_live_[random_string]
Header: Authorization: Bearer sk_live_...

Best Practices#

Never expose your API key in client-side code (Frontend).
Store keys in environment variables (.env.local).
Rotate your keys immediately if you suspect a leak.

💜 2. Nostr Auth (NIP-98)#

For users who want to stay anonymous or integrate directly with the Nostr ecosystem, we support NIP-98 (HTTP Authentication for Nostr).

How it works#

1.
Create a "Kind 27235" event.
2.
Sign it with your Nostr Private Key (nsec).
3.
Base64-encode the signed event JSON.
4.
Pass it in the header as: Authorization: Nostr [base64_encoded_event]

Generation Script (Bash + nostr-tool)#


⚡ 3. Agent Payments (L402 Runtime & Experimental x402 Discovery Adapter)#

For autonomous AI agents and bots that pay per tunnel over the Bitcoin Lightning Network without pre-registered accounts:
Endpoint: Autonomous Agent HTTP 402 Gateway (POST https://tunnelsats.com/api/v1)
Challenge (HTTP 402): Returns WWW-Authenticate: L402 macaroon="...", invoice="lnbc..." (interoperable binary V2 L402 macaroon) and PAYMENT-REQUIRED (experimental x402 v2 discovery adapter envelope with scheme: "l402", network: "bip122:000000000019d6689c085ae165831e93", asset: "SAT", and extra.adapterRole: "discovery").
Credential Header: Authorization: L402 <macaroon>:<preimage> (where SHA256(preimage) == paymentHash), or X-PAYMENT / PAYMENT-SIGNATURE base64 JSON carrying { "macaroon": "...", "preimage": "..." }.
See 🤖 Agent Payments: L402 & x402 Protocol for full Python, Node.js, and Bash examples.

🔒 4. Rate Limiting Strategy#

Our API uses a two-layer rate-limiting system to protect the network.

Layer 1: Cloudflare WAF (Burst Limiter)#

A blanket rule across all /api/public/* paths:
Limit: 10 requests per 10 seconds per IP
Action: Block (with 10s mitigation timeout)
Purpose: Prevents rapid bursts and DDoS attacks

Layer 2: Application Rate Limits (Per-Endpoint)#

Each endpoint has its own limit enforced at the application layer:
EndpointLimitPer
GET /api/v160/minIP
POST /api/v110/minIP
GET /servers60/minIP
POST /create10/minIP
POST /claim10/minIP
GET /{paymentHash}60/minIP
POST /status30/minIP
POST /renew20/minIP
POST /bandwidth-reset10/minIP
POST /{paymentHash}/sync5/minSubscription
GET /list30/minAccount
POST /ping/lookup5/minIP
POST /ping/test3/minIP

Handling 429 Responses#

When you receive an ERR_RATE_LIMIT_EXCEEDED (429), your application MUST implement exponential backoff:
Modified at 2026-10-16 19:46:29
Previous
⚡ Bandwidth Top-Up ($1 Usage Reset)
Next
🎁 Referral Program: Earn Bonus Months
Built with