Skip to content

Loop-XXI/loop-gateway

Repository files navigation

Loop Gateway

Bitcoin-native AI API proxy. Pay-as-you-go in sats. Own your data. Sell it.

Loop Gateway is a drop-in replacement for any OpenAI-compatible client that replaces API keys with Lightning payments, prepaid sat balances, or Cashu ecash. Over 300 models from OpenRouter, priced in real-time sats at a 15% markup over upstream cost (covers platform fee, Lightning routing, and BTC/USD volatility).

No accounts. No KYC. No email. Just sats.


What Makes Loop Gateway Different

Typical AI proxy Loop Gateway
Sign-up Email, password, credit card Pay a Lightning invoice, get a bearer token
Identity Account per user Token per balance — rotate freely
Payment Monthly billing in USD Per-request in sats
Data Silently logged by the provider Encrypted vault the user owns
Monetization Provider profits from your usage User can sell their own conversation history on the marketplace

Features

  • OpenAI-compatible proxy — chat completions, legacy completions, embeddings, images, model listing
  • 300+ models routed through OpenRouter
  • Four auth methods — prepaid bearer tokens, L402, Cashu (Authorization or X-Cashu header), and public endpoints
  • Streaming — SSE pass-through with token-accurate cost reconciliation at stream end
  • Real-time pricing — 3-source median BTC price feed (Kraken, Coinbase, CoinGecko), 60-second cache
  • Transparent markup — 15% above upstream OpenRouter cost, configurable via SMARTSAT_MARKUP env var
  • Data vault — AES-256-GCM encrypted conversation storage, per-account keys derived via SHA-256(domain_separator || VAULT_MASTER_KEY || token_hash)
  • Marketplace — users create priced shares of their vault, buyers pay a single Lightning invoice, sellers withdraw via BOLT11
  • Platform fee — configurable percentage on marketplace sales (default 10%) funds protocol sustainability

Quick Start

Use the live instance

from openai import OpenAI

client = OpenAI(
    base_url="https://api.loopxxi.com/v1",
    api_key="loop-gateway_<your_prepaid_token>",
)

response = client.chat.completions.create(
    model="openai/gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello"}],
)

Get a prepaid token by topping up with Lightning:

curl -X POST https://api.loopxxi.com/v1/topup \
  -H "Content-Type: application/json" \
  -d '{"amount_sats": 5000}'
# Returns: { "token": "loop-gateway_...", "invoice": "lnbc...", "payment_hash": "..." }

Pay the invoice, then use the token as a bearer on subsequent requests.

Self-host

git clone https://github.com/Loop-XXI/loop-gateway.git
cd loop-gateway
cp .env.example .env
# Edit .env — set OPENROUTER_API_KEY and DATABASE_URL
docker compose up

The proxy boots on :8080. Hit /health to verify. See PROJECT-STATUS.md for architecture and docs/handoffs/ for the engineering log.


API Surface

Public (no auth)

GET  /health                          Liveness check
GET  /v1/pricing                      All models with USD and sat pricing
GET  /v1/models                       OpenAI-compatible model list with Loop Gateway overlay
POST /v1/topup                        Create a prepaid token + Lightning invoice
GET  /v1/marketplace                  Browse active vault shares
GET  /v1/marketplace/stats            Aggregate marketplace metrics

Authenticated (prepaid / L402 / Cashu)

POST /v1/chat/completions             Streaming + non-streaming chat
POST /v1/completions                  Legacy completions
POST /v1/embeddings                   Embedding generation
GET  /v1/balance                      Check prepaid balance
GET  /v1/vault/stats                  Vault stats for the authenticated token
POST /v1/vault/share                  Create a priced share of your vault
POST /v1/vault/share/:id/list         Toggle public marketplace listing
GET  /v1/vault/download/:id           Buyer-only decrypted download
POST /v1/vault/withdraw               Pay out seller balance via BOLT11
GET  /v1/vault/seller-balance         Available, pending, lifetime earnings

Architecture

Client → Caddy (TLS) → Loop Gateway (Go/Gin) → OpenRouter (300+ models)
                            │
                    ┌───────┼───────┐
                    │       │       │
               Phoenixd  Postgres  BTC price feed
               (Lightning)         (Kraken / Coinbase / CoinGecko)

Component responsibilities are laid out in PROJECT-STATUS.md. The proxy is pure Go with Gin, under 10k lines excluding tests. The vault uses per-account AES-256-GCM. The marketplace is a pure Postgres feature — no separate service.


Tech Stack

Layer Technology
Language Go 1.23
Web framework Gin
Database PostgreSQL
Lightning Phoenixd (swappable via lightning.Backend interface)
LLM routing OpenRouter
Frontend Vanilla HTML / CSS / JS (single-file, dark minimal)
TLS / proxy Caddy
CI GitHub Actions

Project Status

Loop Gateway is in early production. The core proxy, prepaid flow, vault, and marketplace are live and have served real users. The project is funded by Loop XXI treasury at a planned loss during the acquisition phase — you can read the economics in HANDOFF-18.md.

Open problems we care about:

  • Running a first-party Cashu mint (currently we only accept tokens from trusted external mints)
  • LND and CLN backend implementations alongside Phoenixd
  • Liquid Network top-ups
  • A proper static docs site (the docs/ directory currently hosts the app, not docs)

See CONTRIBUTING.md for how to help.


License

MIT. Copyright (c) 2026 Loop XXI and Loop Gateway Contributors.

Built by Loop XXI — AI infrastructure for the Bitcoin economy.

About

Loop Gateway — OpenAI-compatible LLM API metered in Bitcoin. 300+ models via OpenRouter, prepaid bearer credit (L402), no accounts. api.loopxxi.com

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors