1. Cookbook
TunnelSats Public Wireguard API
  • Announcements
    • 👋 About our team
    • 💫 What is TunnelSats?
    • 🚀 Introducing the TunnelSats Public API v1
    • How TunnelSats Leverages Public APIs for Confined VPN Management
  • 📡 Discovery
    • List Available WireGuard Servers & Regions
      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
  • 🔄 Lifecycle
    • Get Subscription & Bandwidth Status by WireGuard Public Key
      POST
    • Renew an Existing VPN Subscription (Anonymous)
      POST
    • Sync Subscription (Real-Time Server Refresh)
      POST
    • Request Bandwidth Top-Up ($1 for +100GB)
      POST
  • 🔑 Account
    • List Account Subscriptions (Authenticated)
      GET
  • 🔧 Tools
    • Lightning Node Network Address Discovery
      POST
    • Universal Connectivity & Latency Probe
      POST
  • Cookbook
    • 🛠️ Automation & Code Examples
    • 🐚 Bash One-Liners
    • 🚑 Node Health & Upkeep
    • ⚡ Bandwidth Top-Up ($1 for +100GB)
    • 🛡️ Security & Authentication
    • 🎁 Referral Program: Earn Bonus Months
    • 🛑 Error Codes & Troubleshooting
  • Schemas
    • Server
    • InvoiceOrder
    • SubscriptionStatus
    • NodeLookup
    • ConnectivityResult
    • ApiError
    • ClaimResult
    • BandwidthResetResponse
    • PublicKeyStatusResponse
    • RenewalOrder
    • SubscriptionListItem
    • SyncResult
Tunnelsats Github
Tunnelsats Telegram
  1. Cookbook

🛑 Error Codes & Troubleshooting

TunnelSats uses standardized machine-readable error codes. Since our API involves real-world Lightning transactions, understanding these codes is the difference between a smooth automation and a broken one.

📊 Machine-Readable Error Codes

All error responses follow the ApiError schema: {"error": "CODE", "message": "Reason"}.

CodeHTTPMeaningMitigation
ERR_INVALID_INPUT400Invalid serverId, duration, malformed pubkey, bandwidth usage below threshold (<70%), or expired subscription.Check request payload and verify subscription status.
ERR_UNAUTHORIZED401Missing or invalid Authorization header.Use Bearer <api_key> or Nostr <token>.
ERR_PAYMENT_REQUIRED402Subscription exists but hasn't been paid yet.Poll the status until it returns paid.
ERR_MIGRATION_REQUIRED403Attempting to renew on a legacy server (us1).Use the migration tool to move to us3.
ERR_RESOURCE_NOT_FOUND404No subscription found for that paymentHash.Verify your hash from the /create call.
ERR_RATE_LIMIT_EXCEEDED429Rate limit exceeded or maximum monthly bandwidth resets reached (max 2/month).Implement exponential backoff or wait for monthly reset counter to refresh.
ERR_INTERNAL_ERROR500Internal server error.Wait 30 seconds and retry.
503503Backend VPN server unavailable or syncing (retryable).Retry with exponential backoff. This is common during bandwidth-reset webhook processing if the VPN manager is temporarily unreachable.

⏱️ Rate Limits by Endpoint (Source Code)

Two layers protect the API: a Cloudflare WAF burst limiter (10 req/10s per IP across all /api/public/*) and per-endpoint application limits:

EndpointLimitWindowKey
GET /servers60/min60sPer IP
POST /create10/min60sPer IP
POST /claim10/min60sPer IP
GET /{paymentHash}60/min60sPer IP
POST /status30/min60sPer IP
POST /renew20/min60sPer IP
POST /bandwidth-reset10/min60sPer IP
POST /{paymentHash}/sync5/min60sPer subscription
GET /list30/min60sPer account
POST /ping/lookup5/min60sPer IP
POST /ping/test3/min60sPer IP

🔍 Specific Scenarios

WARNING

402 vs. 404

If a user waits too long to pay, the invoice will expire.

  • Scenario: You poll and keep getting ERR_PAYMENT_REQUIRED.
  • Expiry: If the invoice expires, the paymentHash may eventually return ERR_RESOURCE_NOT_FOUND.
  • Action: Generate a new subscription request via /create.

DANGER

ERR_RATE_LIMIT_EXCEEDED

Our public endpoints are rate-limited to ensure availability for all node operators.

  • Burst Limit (Cloudflare): 10 requests/10 seconds across all public API paths.
  • Per-Endpoint Limits: See the table above for exact limits per operation.
  • Mitigation: Implement an exponential backoff. If you hit a 429, wait 10 seconds before trying again.

INFO

Cloudflare Access Bypass

Requests to dev2.tunnelsats.com require Cloudflare Service Tokens.

  • Headers Required:
    • CF-Access-Client-Id
    • CF-Access-Client-Secret
  • Failure: Missing these will return a 302 Redirect to a login HTML page.
Modified at 2026-09-02 06:15:00
Previous
🎁 Referral Program: Earn Bonus Months
Next
Server
Built with