L402 · NWC · MCP × Lightning · Agent2Agent

Agentic Payments
AI Agent × Lightning Network の交差点

LLM ベースの autonomous AI agent が API 呼び出し・データ購入・他 agent との取引を行うようになると、 従来の credit card / OAuth では機能しない(API ごとの少額決済、24時間自律、機械間 settlement)。 Lightning Network は マイクロペイメント × プログラマブル × 24/7という条件を唯一満たす layer であり、 L402 (HTTP 402)NWC (Nostr Wallet Connect)MCP × Lightningを中核に新しいエコシステムが急成長している。

主要 protocolL402 · NIP-47 NWC · A2A
推進 playsLightning Labs · Fewsats · Alby · Mash
関連 frameworkLangChain · MCP · ElizaOS · Goose
現在の status2024–25 急成長期 / spec 進化中
HTTP 402
復活した status code
M2M
machine-to-machine
~ 1 sat
最小単位 payment
NWC
agent → wallet 制御
§ 1 · Why Lightning for AI Agents?

Web2 決済 layer が agent には不向きな理由

要件Credit cardStripe APILightning
最小金額~$0.50 (手数料下限)~$0.30~$0.0001 (1 sat)
API call ごとの決済不可 (高すぎ)可だが高額最適
事前 KYC / oauth必須必須不要
24/7 機械操作時々止まる
機械間 settlement企業間契約必要marketplace 必要peer-to-peer
refund / chargeback攻撃面運用負荷irreversible
地理的制限ありありなし

本質的に: agent は「人間用の決済 layer」を使えない

現代の AI agent は 1 task 完了に数百回 API callを行う場合がある (web search → LLM call → tool call → RAG retrieval ...)。これらが 1 件 $0.001–$0.01 で動的に計上されるため、 credit card の最小手数料を下回る。Stripe や PayPal のようなアカウントベース決済では、agent ごとの KYC 不可能。 Lightning は "少額 + 即時 + 機械可動 + 国境なし" を唯一満たすため、agent payment infrastructure として急速に位置づけが固まりつつある。

§ 2 · L402 (旧 LSAT)

HTTP 402 を復活させた agent-friendly auth

Lightning Labs · Aperture project 2018 LSAT → 2023 L402 rebrand

L402 = Lightning + 402。HTTP の status code 402 "Payment Required" を再活用し、 API call ごとに少額決済を要求する protocol。Macaroon (Google 由来の cookie-like token) と Lightning preimage を組み合わせる。

HTTP 402 フロー

→ RequestGET /api/translate?text=hello
Header(no Authorization)
 
← ResponseHTTP/1.1 402 Payment Required
HeaderWWW-Authenticate: L402 macaroon="MDAxMG...", invoice="lnbc100n1p3..."
 
Agent:Pay invoice via Lightning → get preimage R
 
→ RetryGET /api/translate?text=hello
HeaderAuthorization: L402 <macaroon>:<preimage_R>
 
← ResponseHTTP/1.1 200 OK
Body{"translation":"こんにちは"}

核心の発明: macaroon × preimage

  • Macaroon: Google 開発の bearer token。第 3 者でも caveats (制約) を追加できる
  • Server が macaroon と Lightning invoice を 402 response に同梱
  • Agent が invoice を払う → preimage Rを取得
  • retry 時に L402 <macaroon>:<R> を送信 → server が R をデータベースで検証
  • Macaroon は 有効期間 / call 数 / scopeを caveats で制限可能

L402 の典型的応用

API Gateway 型

既存 web API を Aperture (Lightning Labs reverse proxy) でラップ。1 行 nginx config 風に L402 課金 wall を追加可能。

Per-call subscription

1 macaroon = N call まで使える subscription token。LLM API 課金 / data feed access。

Tiered pricing

caveats で price tier を埋め込む。"basic / pro / enterprise" を on-the-fly 切替。

Multi-step workflows

agent が複数 API を組み合わせる際、L402 token を state として持ち回ることができる。

主要 L402 deployment

Service分野採用形態
ApertureL402 reverse proxy (Lightning Labs)OSS infrastructure
FewsatsL402-as-a-serviceSaaS for API providers
Lightning PolarOSS regtest environmentSDK demo
Lightning.videovideo pay-per-viewL402 で content unlock
Sphinx Chatmessaging + paid AI toolsL402 on tribes
L402 SDKsJS / Python / Go / Rust各言語クライアント
§ 3 · Nostr Wallet Connect (NIP-47)

Agent から wallet を remote 制御する standard

Nostr NIP-47 Alby / Mutiny lead 2023+

NWC (Nostr Wallet Connect)Nostr プロトコル経由で AI agent や dapp が ユーザー所有の wallet を remote 制御できる standard。 ユーザーが connection URI を生成し、agent に渡すと、agent はその scope 内で支払いを実行できる。NIP-47 として標準化。

NWC connection の流れ

📱 User Wallet Alby / Mutiny / etc. 🌐 Nostr Relay encrypted message bus 🤖 AI Agent LangChain / MCP / etc. NIP-04 encrypted DM 経由でリクエスト/レスポンス Wallet が agent の "pay_invoice" 等を実行 → 結果を返す

connection URI

# User が wallet で生成 → agent に渡す nostr+walletconnect://abc123...?relay=wss://relay.getalby.com&secret=def456... # 構成要素 - pubkey: agent が wallet と通信するための識別子 - relay: Nostr relay (NIP-47 message を中継) - secret: encryption key (NIP-04) - caveats: 任意 (max_amount, expiry, scope) # Agent が使える主要 method {"method":"pay_invoice","params":{"invoice":"lnbc100n1..."}} {"method":"make_invoice","params":{"amount":1000}} {"method":"get_balance"} {"method":"list_transactions"} {"method":"pay_keysend","params":{"pubkey":"02ab...","amount":500}}

✅ NWC の利点

  • 非カストディアル — 秘密鍵は wallet 内
  • Nostr 上で standard 化済み (NIP-47)
  • budget caveats で scope 制限可能
  • any wallet × any agent の interoperable

⚠ 課題

  • Nostr relay に依存 (中央化リスク軽減)
  • session 管理 (revocation / rotation)
  • budget overflow 防止 (caveats 設計)
  • privacy: relay は metadata 観察可能
§ 4 · MCP × Lightning

Anthropic MCP server に "決済壁" を組み込む

Model Context Protocol (MCP) は Anthropic が 2024 末に公開した、LLM (Claude 等) が外部 tool / data source と接続する standard。 MCP server をホストする側は、agent からのリクエストに L402 で課金することで 持続可能な API monetizationを実現できる。

🤖 LLM Agent Claude / GPT / etc. MCP Server (paid) L402 wall tools / resources premium data / weather / web search → per-call price 0.001–0.01 USD ⚡ Wallet via NWC connection ① Claude calls MCP tool ② MCP server returns 402 with invoice ③ Agent → NWC → wallet pays → preimage → MCP returns data

MCP server が L402 を組み込む典型コード

# MCP server (Python with L402 middleware) from mcp import Server from l402 import require_payment server = Server("premium-search-mcp") @server.tool("web_search") @require_payment(amount_sats=10) # 1 call = 10 sat def web_search(query: str) -> dict: return brave_search.query(query) @server.tool("premium_data") @require_payment(amount_sats=100) # tier 2 def premium_data(asset: str) -> dict: return fetch_premium_feed(asset)

この設計により、MCP server を hosting する個人・企業が "使われた分だけ収益化" できる。Claude 等の主要 agent が NWC ↔ MCP に対応すれば、 OSS MCP server marketplace が成立する可能性がある。

§ 5 · Use Cases

Agent × Lightning の代表的応用

Pay-per-API
📊
Data marketplace
🧠
Inference market
📰
Content unlock
🤖
Agent2Agent
🔄
Autonomous agent
§ 6 · Ecosystem Players (2024–25)

主要プロジェクト・サービス

Infrastructure / SDK

Lightning Labs · Aperture

L402 reverse proxy

L402 / LSAT の reference 実装。任意 web API を nginx 風に "課金 wall" 化。OSS。Loop / Pool でも内部使用。

Fewsats

L402-as-a-service

2024 創業。API provider 向けの L402 SaaS。SDKs (JS / Python) を提供し、Stripe ライクな UX で Lightning 課金を導入可能に。

Alby (Get Alby)

NWC / wallet hub

NWC の reference 実装。Alby Hub (LDK Node) + Browser Extension。dapp / agent から user wallet を remote 制御可能にする中心 player。

Mash

monetization platform

web 上での micropayment / paywall を Lightning でワンタップ実現。content creator / SaaS 向け。

Agent frameworks 連携

LangChain Bitcoin Tools

community plug-ins

LangChain / LangGraph の tool として Lightning 支払い・残高確認を提供。OSS。実験段階だが採用増加中。

ElizaOS (a16z Crypto)

crypto-native agent OS

2024 末公開の agent framework。Bitcoin / Solana / Lightning native 対応。L402 / NWC との統合がロードマップ。

Goose (Block / Square)

open AI agent framework

Block (旧 Square) が公開した OSS agent framework。Bitcoin native の design 思想。Cash App との連携検討中。

Sphinx Chat / SphinxAI

paid AI assistant

Lightning native messaging に組み込まれた AI agent。tribe 内での paid query / 機械間 settlement。

関連 standard / spec

Standard用途status
L402 (RFC draft)HTTP 402 + Macaroon + LN preimagede-facto
NIP-47 NWCNostr 経由 wallet remote controlstandardized
NIP-57 (Zaps)Lightning tipping over Nostrstandardized
BOLT 12 Offersrecurring / static endpointsBOLT spec
Bitcoin MCPMCP × Lightning serverscommunity spec
UMA (Lightspark)Universal Money Addressopen spec
Agent2Agent (A2A)agent 間 negotiation + 決済research
§ 7 · Risks & Open Problems

Agent payment 導入の課題

★★★

Runaway agent / budget overflow

autonomous agent が 無限 loopで支払い続ける failure mode。NWC caveats / hard cap / circuit breaker の設計が必須。

★★

Prompt injection → unauthorized payment

第 3 者 web content 経由で agent に「払え」と注入される攻撃。scope confinement + human approval が必要。

★★

Privacy of agent traffic

agent の payment pattern は habit を露出。Nostr relay / LSP が観察可能。BOLT 12 blinded path 推奨。

★★

Rate limit vs micropayment

"1 sat 数千 call" は LN routing には負荷大。MPP / streaming payment / aggregation の設計余地。

★★

Refund / dispute resolution

Lightning は irreversible。agent が誤って高額支払い → 取り戻せない。escrow / partial-refund protocol が未確立。

★★

標準化の合意

L402 / NWC / A2A の各 spec が並列発展。interop standard の確立が遅れている。

Security best practices (2026 時点の community 共通理解)

  • Agent には 専用 sub-wallet を割り当て、母 wallet と分離
  • NWC connection に budget cap (例: $10/day) を必ず設定
  • 高額支払いには human in the loop
  • Anomaly detection: agent payment pattern を monitor
  • L402 macaroon に有効期限・use count caveats を埋め込む
§ 8 · Research Opportunities

Agentic Payments の未解決研究領域

研究

Agent identity vs reputation

「この agent を信頼できるか」を on-chain or LN 上で証明する仕組み。Sybil 耐性のある reputation 設計。

研究

Streaming payment

1 sat × 数千 call の代わりに continuous streaming payment (例: keysend ストリーム / channel 内連続更新) で routing 負荷を下げる設計。

研究

Agent2Agent negotiation protocol

2 agent が price negotiation + atomic settlement を行うプロトコル。Schnorr/MuSig2 + LN HTLC の組み合わせ。

研究

Privacy-preserving agent payment

LSP / Nostr relay が agent の payment pattern を学習しない設計。ZKP-based attestation。

研究

Inference market 経済モデル

分散 LLM inference の pay-per-token 市場。価格発見・QoS 保証・spam 対策の game theory モデル。

研究

Refund / escrow on Lightning

Lightning の irreversibility 制約下での conditional refund 設計。adaptor signature + time lock。

研究

Agent jamming / DoS

悪意 agent が大量 micropayment で LN routing を圧迫する DoS 攻撃面。HTLC Endorsement との接続。

研究

Formal model of agentic payments

「自律 agent + 不可逆決済 + LLM 不確定性」を組み合わせた formal security definition。新領域。

論文化機会

Agentic Payments は 2024-25 で 急速に立ち上がった分野であり、formal な研究はまだ少ない。 既存 wiki の jamming / privacy / economics 研究と接続することで、 新規性の高い paper(FC / IEEE S&P / USENIX Security 級)を出せる余地が大きい。 特に "runaway agent の formal mitigation" "agent reputation の Sybil 耐性"あたりは未開拓。

§ 9 · Resources & Related Pages

関連

本サイト内のビジュアル解説

主要リファレンス

  • 📜 L402 spec — github.com/lightninglabs/aperture
  • 📜 NIP-47 NWC — github.com/nostr-protocol/nips/blob/master/47.md
  • 📰 Lightning Labs blog — "L402: The Lightning HTTP 402 Protocol" (2023 rebrand)
  • 🔧 Aperture — Lightning Labs reverse proxy
  • 🔧 Fewsats — fewsats.com (L402-as-a-service)
  • 🔧 Alby Hub — getalby.com (NWC + LDK Node)
  • 🔧 Mash — mash.com (web monetization)
  • 🔧 ElizaOS — a16z Crypto agent framework
  • 🔧 Goose — block.github.io/goose (OSS agent)
  • 🔧 Anthropic MCP — modelcontextprotocol.io
⚠ この分野は 2024–25 年で急速に進化中。本ページは 2026 Q2 時点の整理。具体的な service 状況は現地サイトで最新情報を確認してください。