API & WebSocket Reference
Base URL (Production): https:
Base URL (Local Dev): http:
1. OpenAI-Compatible Inference API (/v1/* )
Authenticated via Authorization: Bearer sk_ (SHA-256 verified against api_).
GET /v1/models
Returns all active canonical models from PostgreSQL models enriched with live online_ counts from Redis + the WebSocket Hub.
POST /v1/chat/completions
Executes OpenAI-compatible chat completion (stream: true SSE or stream: false JSON).
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Canonical model ID (e.g., qwen3-, qwen3-, llama-) |
messages | array | Yes | Standard [{role, content}] conversation turns |
max_ | int | No | Default 256. Used for pre-flight escrow calculation |
temperature | float | No | Default 0. |
stream | bool | No | When true, streams text/ (data: {., terminating with data: [DONE]) |
seed | int64 | No | Optional deterministic seed forwarded to worker engine |
2. Authentication API (/api/auth/* )
Sessions use Argon2id password hashing and HS256 JWT tokens delivered both as Http cookies (tenson_) and JSON token for native desktop/CLI clients.
| Endpoint | Method | Body / Headers | Response |
|---|---|---|---|
/ | POST | {email, password, role} (buyer/seller/both) | 201 {user, token} |
/ | POST | {email, password} | 200 {user, token} |
/ | POST | Session cookie | 200 {ok: true} |
/ | GET | Session cookie or Bearer <jwt> | 200 {user} |
3. Management & Billing API (/api/* )
All endpoints below require a valid user session (401 Unauthorized otherwise) and are strictly scoped to claims..
| Endpoint | Method | Purpose |
|---|---|---|
/ | GET, POST | List active API keys or create a new SHA-256 key (one-time secret reveal) |
/ | DELETE | Revoke an API key immediately |
/ | GET | Return available balance (SUM(amount)) and immutable ledger_ |
/ | POST | Create a Stripe Checkout session ({amount_) returning {checkout_ |
/ | GET | Zero-log metadata-only inference_ history |
/ | POST | Generate a single-use nt_ worker token persisted in nodes |
/ | GET | Live Redis telemetry + PostgreSQL audit_ for a node |
/ | POST | Create/reuse Stripe Connect Express account & return {onboarding_ |
/ | GET | Return withdrawable_, holdback_ (7d), and payouts history |
/ | POST | Withdraw >= 25, ($25.) via Stripe Connect Express transfer |
4. Public Telemetry, Webhooks & Observability
| Endpoint | Method | Purpose |
|---|---|---|
/ | GET | Live online nodes, pooled VRAM, aggregate TPS, and reconciliation_ invariant |
/ | POST | HMAC-verified (Stripe-) Stripe Checkout & Connect webhook receiver |
/ | GET | Live PostgreSQL 16 + Redis 7 connectivity probe |
/ | GET | Prometheus text exposition (tenson_, tenson_, tenson_) |
5. Worker WebSocket Protocol (/ws/worker )
Persistent outbound JSON-framed WebSocket tunnel initiated by tenson-:
- Worker → Gateway:
register({type, node_)token, version, hostname, region, hardware, models, max_ concurrent} - Gateway → Worker:
register_(ack {type, node_)id, heartbeat_ interval_ ms: 5000, reputation_ score} - Worker → Gateway (every 5s):
heartbeat({type, active_)jobs, avg_ tps, gpu_ util_ pct, vram_ free_ gb} - Gateway → Worker:
job_(request {type, job_)id, model, messages, max_ tokens, temperature, seed} - Worker → Gateway (streaming):
token_(chunk {type, job_)id, seq, delta} - Worker → Gateway:
job_(complete {type, job_)id, prompt_ tokens, completion_ tokens, finish_ reason} - Bidirectional:
job_(cancel {type, job_)id, reason}