Consensus Protocol proxy, WebSocket and tunnel service supporting x402 payments.
consensus is an early-stage TypeScript project in the AI payments / x402 ecosystem, focused on api, axios, client, coinbase. It currently has 5 GitHub stars and 0 forks, and sits alongside related tools like tdm-integration-kit, tdm-sdk, TDM-Agent-Integration-Kit.
HTTP deduplication protocol with secure, verifiable payments via x402
HTTP as it should be for modern blockchains. Protect your APIs from the chaos of consensus
Built for decentralization. Runs on a Raspberry Pi
• Docs • Demo • Testnet Transactions
Blockchain consensus algorithms are powerful — but they come with baggage.
On the Internet Computer (ICP), for example, when an application subnet performs an HTTP outcall, each node in the subnet independently makes the request. These nodes run replicas, and the responses from the HTTP outcalls are compared in the consensus process. This means:
This especially becomes a problem when your target endpoint is not idempotent.
Even if only one response is used, your service may still receive multiple requests, potentially triggering duplicate processing, double charges, or conflicting writes.
With Consensus Proxy, only 1 request is executed — no matter how many are sent. In consensus-based systems like ICP, this reduces outbound traffic by up to ~93%. It also eliminates duplicate hits that waste resources, exceed rate limits, or create billing issues.
Whether your backend is a serverless function, a rate-limited SaaS API, or a payment gateway, Consensus Proxy ensures you pay once, process once — regardless of how many nodes, retries, or consensus rounds are involved.
Consensus Proxy solves this problem at the protocol level.
It acts as a deduplication layer that:
Without deduplication, every replica sends its own request — resulting in N-1 redundant API hits per consensus round.
With Consensus Proxy, the first request triggers an x402 payment challenge. The client retries using a wrapper (like fetch-with-payment), and upon successful verification, the proxy settles the request, makes the external call, and caches the result for reuse.
sequenceDiagram
participant R1 as Node 1
participant R2 as Node 2
participant R3 as Node 3
participant P as Proxy (x402-protected)
participant API as External API
participant C as Consensus
R1->>P: HTTP outcall (idempotency: icp23072025, x-api-key: ba137)
R2->>P: HTTP outcall (idempotency: icp23072025, x-api-key: ba137)
R3->>P: HTTP outcall (idempotency: icp23072025, x-api-key: ba137)
Note right of P: First request → cache MISS → x402 challenge
P-->>R1: 402 Payment Required (x402 challenge)
R1->>P: Retry using fetch-with-payment
Note right of P: Payment verified → request settled
P->>API: External API call(eg: coinGecko)
API-->>P: Response: {"usd": 6.09}
Note right of P: Response cached → reused for remaining requests
P-->>R1: Cached response
P-->>R2: Cached response
P-->>R3: Cached response
R1->>C: Process response → State A
R2->>C: Process response → State A
R3->>C: Process response → State A
C-->>R1: Consensus reached
C-->>R2: Consensus reached
C-->>R3: Consensus reached
Note right of C: All replicas receive the same response
The protocol spans three repos:
| Repo | Role |
|---|---|
| consensus (this repo) | server/ — the orchestrator/proxy that runs at the network edge. |
| consensus-client | @canister-software/consensus-cli — TypeScript SDK + CLI used to interact with the network. |
| consensus-node | Bun worker-node runtime that registers with the orchestrator and serves proxied requests. |
Architecture direction: the proxy and tunnel data paths are moving to a control-plane / data-plane split — the orchestrator authenticates, charges (x402), selects a node, and issues a signed ticket, after which the client connects directly to that node. The orchestrator serves traffic itself only when no other node is available.
The CLI is not yet published to npm. For now, clone consensus-client and run it with Bun.
Once published, the CLI + SDK will be available as @canister-software/consensus-cli:
npm install @canister-software/consensus-cli
Until then, run it from source:
git clone https://github.com/Demali-876/consensus-client
cd consensus-client && bun install
Consensus proxy currently uses CDP to configure the client wallet to interact with the x-402 server. In the future we will support browser wallets.
Create a .env file:
CDP_API_KEY_ID=your_api_key_id
CDP_API_KEY_SECRET=your_api_key_secret
CDP_WALLET_SECRET=your_wallet_secret
bun run setup # in the consensus-client repo
This generates:
curl -X POST http://localhost:3001/proxy \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: icp-price-check" \
-d '{"target_url": "https://api.coingecko.com/api/v3/simple/price?ids=internet-computer&vs_currencies=usd"}'
Returns:
{
"status": 200,
"data": {
"internet-computer": {
"usd": 6.09
}
}
}
Want raw metadata, proof of payment, or debug info? Add the header
X-Verbose: trueto get the full payload.
{
"status": 200,
"statusText": "OK",
"data": {
"internet-computer": {
"usd": 6.09
}
},
"timestamp": 1753129159138,
"cached": false,
"payment_required": true,
"billing": {
"cost": "$0.001",
"reason": "payment_processed",
"idempotency_key": "icp-price-check9",
"processing_time_ms": 3045
},
"meta": {
"wallet_name": "0cc495c8c94834b3", // In practice, you should not reveal your wallet name.
"account_address": "0x7d19e332F1b84D783bd7FeA5B6aa0b809B9A80A4",
"idempotency_key": "icp-price-check9",
"processing_time_ms": 3143,
"x402_proxy_handled": true,
"timestamp": "2025-07-21T20:19:19.142Z"
}
}
Consensus Proxy is language agnostic and is pure HTTPS. This means you can make a request from any language on any platform. You can use Motoko, Javascript/Typescript, Rust, Python, curl to interact with the Consensus server.
This project is licensed under the Business Source License 1.1 (BUSL-1.1).
The Licensed Work is:
For full terms, see the LICENSE file.
Developer integration tools for adding TDM payments to AI agents, apps, and workflows. CLI, MCP server, and copy-paste examples
Open contract-facing SDK for payable routes and gateway-backed integrations. Thin public surface for authorize, checkout, and session flows.
Developer integration tools for adding TDM payments to AI agents, apps, and workflows. CLI, MCP server, and copy-paste examples