p2ptokens documentation

A distributed, peer-to-peer, decentralized network for LLM inference. One app both seeds (serves completions from a local model) and leeches (consumes completions from peers), gated by a no-free-lunch upload/download ratio — the seed/leech incentive model of the BitTorrent protocol, applied to inference. A central coordinator brokers matches but never sees your data; the inference bytes flow directly peer-to-peer.

Overview

p2ptokens has three pieces:

ComponentBinaryRole
Clientp2ptokensUnified seeder + leecher; exposes a local OpenAI-compatible /v1 endpoint and a dashboard.
Coordinatorp2p-coordinatorContent-blind tracker: registry, O(1) matchmaker, barter-ratio ledger, co-receipt settlement.
Desktopp2ptokens-desktopTauri app that embeds the client in a native window.

You bring your own model backend (Ollama, any OpenAI-compatible endpoint, or Claude). See the architecture for the full picture.

Quickstart

Requires Ollama with a model pulled.

ollama pull llama3.2:3b
cargo build

# terminal 1 — the tracker
target/debug/p2p-coordinator

# terminal 2 — a seeder (serves your local Ollama)
target/debug/p2ptokens --http 127.0.0.1:8080 --data-dir ./.p2p/a

# terminal 3 — a leecher
target/debug/p2ptokens --http 127.0.0.1:8081 --data-dir ./.p2p/b

Open the dashboard at http://127.0.0.1:8081, or call the drop-in /v1 endpoint:

curl http://127.0.0.1:8081/v1/chat/completions \
  -H 'content-type: application/json' \
  -d '{"model":"llama3.2:3b","messages":[{"role":"user","content":"hi"}],"stream":true}'

One-shot end-to-end smoke test: bash scripts/e2e.sh.

Install

Works on macOS, Linux, and Windows — no system dependencies (TLS is statically vendored, so Linux needs no OpenSSL).

Desktop app (recommended)

A double-click app (.dmg/.msi/.AppImage) that embeds the P2P daemon and opens the dashboard — still 100% peer-to-peer.

CLI

# prebuilt binaries
curl -fsSL https://p2ptokens.com/install.sh | sh          # macOS / Linux
irm https://p2ptokens.com/install.ps1 | iex               # Windows

# or with Cargo
cargo install --git https://github.com/pur4v/p2ptokens p2ptokens-client p2ptokens-coordinator

The identity keypair is stored in the per-OS data dir (override with --data-dir).

API — /v1

The client serves a drop-in OpenAI-compatible surface. Point any tool's base URL at http://127.0.0.1:8081/v1.

RouteNotes
POST /v1/chat/completionsStreaming ("stream":true, SSE) and non-streaming. Response includes p2p_provider (the peer that served it).
GET /v1/modelsNetwork-wide model list.
GET /api/statusNode status: peer id, ratio, offers, swarm.
GET /api/configBrand/network config the dashboard renders (white-label).
Tool calling and /v1/responses are on the roadmap (needed for agent workflows); today the surface is chat-completions + models.

Fan-out — one prompt, many peers

By default a request goes to one peer. You can fan a single prompt out to several:

ModeBehaviorUse for
singleone provider (default; streams)normal chat
racingdial K, return the fastest full completionlowest latency
quorumdial K, return the majority answer + agreement countredundancy / catch a bad peer
ensembledial K, return all answers as separate choicescompare models

Select it three ways:

# 1) request field
-d '{"model":"llama3.1:8b","fanout":"quorum","fanout_count":3,"messages":[...]}'

# 2) model-name prefix (works with any OpenAI client)
-d '{"model":"ensemble:llama3.1:8b","messages":[...]}'

# 3) the dashboard's Chat panel has a mode dropdown + peer count

Each peer is metered by its own co-receipt; fan-out modes are non-streaming (they coordinate results).

Dashboard

The client serves an ASCII terminal-themed console with two tabs:

Bring your own backend

Backends are configured via environment variables (matched by model name):

export P2P_OLLAMA=1                         # local Ollama (on by default)
export P2P_ENDPOINT_URL=https://host/v1  P2P_ENDPOINT_KEY=...  P2P_ENDPOINT_MODELS=a,b
export ANTHROPIC_API_KEY=sk-ant-...      P2P_CLAUDE_MODELS=claude-3-5-sonnet-latest
Note: proxying paid/hosted API access to strangers may violate that provider's terms. User-borne risk by design; only Ollama (local) is risk-free.

Configuration

One p2ptokens.toml configures everything. Precedence (highest first): CLI flags > env vars > p2ptokens.toml > built-in defaults. With no file and no flags you join the public network with default branding.

[network]     id="public"  name="p2ptokens"  private=false  join_secret=""
[coordinator] url="https://coordinator.p2ptokens.com"  listen="127.0.0.1:4000"
[relay]       addr=""            # optional relay multiaddr to reserve a slot on
[client]      http="127.0.0.1:8080"  p2p_listen="/ip4/0.0.0.0/tcp/0"  capacity=4  relay=false
[brand]       product_name="p2ptokens"  tagline="…"  accent="#33ff88"  amber="#ffb000"
              website="https://p2ptokens.com"  github="…"  logo_url=""

Load with --config p2ptokens.toml (or place it in the working dir, or set $P2PTOKENS_CONFIG). Override any single value with a flag, e.g. --network-id acme --join-secret …. A fully-commented template ships as p2ptokens.example.toml.

Run your own network self-host

p2ptokens is a platform — fork it and run your org's own private, branded swarm.

cp p2ptokens.example.toml p2ptokens.toml   # edit [network]/[coordinator]/[brand]

p2p-coordinator --config p2ptokens.toml    # your coordinator (private → needs the secret)
p2ptokens --config p2ptokens.toml          # each org machine joins the same network + secret
Set in configEffect
network.idIsolation — peers on a different id can't open a stream to yours (scoped libp2p protocol).
private + join_secretPrivate gate — the coordinator rejects any request without Authorization: Bearer <secret>.
coordinator.url / relay.addrPoint clients at your coordinator and relay.
[brand]White-label the dashboard live via /api/config — no rebuild.
v1 note: coordinator state is in-memory (single instance, no DB yet). Fine for a team; for HA, externalize the registry/ledger to Redis/Postgres (roadmap).

Running across NAT

Like a modern peer-to-peer client, p2ptokens does the full traversal stack: identify + AutoNAT + UPnP + circuit-relay + DCUtR hole-punching. Run one public relay; peers behind home routers reserve a /p2p-circuit slot and become reachable, with DCUtR upgrading to a direct connection when possible.

# public relay (no backends needed)
P2P_OLLAMA=0 target/debug/p2ptokens --relay --p2p-listen /ip4/0.0.0.0/tcp/4001
# a client using it
target/debug/p2ptokens --relay-addr /ip4/<relay-ip>/tcp/4001/p2p/<relay-peer-id>

The economy

Access is a no-free-lunch upload/download ratio — you earn the right to leech by seeding. This is p2ptokens' core differentiator; it makes a market where strangers can trade compute without getting cheated.

Architecture

The control plane (HTTP, metadata only) and the data plane (libp2p, peer-to-peer) are separate — the coordinator brokers matches and moves the ratio, but the inference bytes never touch it.

p2ptokens architecture — content-blind coordinator, P2P data plane, relay, fan-out

Security & privacy

Honest limit: in v1 the serving peer sees prompts in plaintext — there is no TEE/sandbox yet (contractual only). v1 is for non-sensitive workloads.

Reliability & abuse limits

A swarm is only useful if a flaky, slow, or hostile peer can't wedge your request. p2ptokens hardens the failure paths, not just the happy path:

Configure per node in p2ptokens.toml: [client] max_input_bytes, max_output_tokens.

FAQ

Do I need a GPU?

Only if you want to seed a model fast. You can run leech-only; but access is ratio-gated, so a machine that serves nothing will hit the newcomer-grace limit and then be throttled until it seeds.

Does the coordinator see my prompts?

No. It only brokers matches and moves the ratio. Your prompt goes directly to the serving peer over an encrypted libp2p stream. (That peer does see it — see the honest limit above.)

Can I run a fully private network for my org?

Yes — see Run your own network: set a network.id (isolation) and a join_secret (private gate), and brand it via [brand].

Is there money involved?

Not in v1 — it's pure barter (a ratio). No wallets, no KYC.

What models can I use?

Anything your backend serves: local Ollama models, any OpenAI-compatible endpoint, or Claude (BYO credentials). Matching is by model name.