Skip to main content

API & WebSocket Reference

Base URL (Production): https://api.tenson.app
Base URL (Local Dev): http://127.0.0.1:8080


1. OpenAI-Compatible Inference API (/v1/*)​

Authenticated via Authorization: Bearer sk_tenson_live_... (SHA-256 verified against api_keys).

GET /v1/models​

Returns all active canonical models from PostgreSQL models enriched with live online_nodes counts from Redis + the WebSocket Hub.

POST /v1/chat/completions​

Executes OpenAI-compatible chat completion (stream: true SSE or stream: false JSON).

FieldTypeRequiredDescription
modelstringYesCanonical model ID (e.g., qwen3-8b, qwen3-30b, llama-3.3-70b)
messagesarrayYesStandard [{role, content}] conversation turns
max_tokensintNoDefault 256. Used for pre-flight escrow calculation
temperaturefloatNoDefault 0.7
streamboolNoWhen true, streams text/event-stream (data: {...}\n\n, terminating with data: [DONE])
seedint64NoOptional deterministic seed forwarded to worker engine

2. Authentication API (/api/auth/*)​

Sessions use Argon2id password hashing and HS256 JWT tokens delivered both as HttpOnly; SameSite=Lax cookies (tenson_session) and JSON token for native desktop/CLI clients.

EndpointMethodBody / HeadersResponse
/api/auth/registerPOST{email, password, role} (buyer/seller/both)201 {user, token}
/api/auth/loginPOST{email, password}200 {user, token}
/api/auth/logoutPOSTSession cookie200 {ok: true}
/api/auth/meGETSession 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.UserID.

EndpointMethodPurpose
/api/keysGET, POSTList active API keys or create a new SHA-256 key (one-time secret reveal)
/api/keys/{id}DELETERevoke an API key immediately
/api/billing/ledgerGETReturn available balance (SUM(amount)) and immutable ledger_entries
/api/billing/checkoutPOSTCreate a Stripe Checkout session ({amount_usd}) returning {checkout_url}
/api/logsGETZero-log metadata-only inference_jobs history
/api/nodes/registerPOSTGenerate a single-use nt_tenson_live_... worker token persisted in nodes
/api/nodes/{id}/metricsGETLive Redis telemetry + PostgreSQL audit_logs for a node
/api/seller/stripe/onboardPOSTCreate/reuse Stripe Connect Express account & return {onboarding_url}
/api/payoutsGETReturn withdrawable_points, holdback_points (7d), and payouts history
/api/payouts/requestPOSTWithdraw >= 25,000 pts ($25.00) via Stripe Connect Express transfer

4. Public Telemetry, Webhooks & Observability​

EndpointMethodPurpose
/api/public/grid-statsGETLive online nodes, pooled VRAM, aggregate TPS, and reconciliation_ok invariant
/api/webhooks/stripePOSTHMAC-verified (Stripe-Signature) Stripe Checkout & Connect webhook receiver
/healthzGETLive PostgreSQL 16 + Redis 7 connectivity probe
/metricsGETPrometheus text exposition (tenson_gateway_requests_total, tenson_ledger_reconciliation_diff, tenson_online_nodes)

5. Worker WebSocket Protocol (/ws/worker)​

Persistent outbound JSON-framed WebSocket tunnel initiated by tenson-worker:

  1. Worker → Gateway: register ({type, node_token, version, hostname, region, hardware, models, max_concurrent})
  2. Gateway → Worker: register_ack ({type, node_id, heartbeat_interval_ms: 5000, reputation_score})
  3. Worker → Gateway (every 5s): heartbeat ({type, active_jobs, avg_tps, gpu_util_pct, vram_free_gb})
  4. Gateway → Worker: job_request ({type, job_id, model, messages, max_tokens, temperature, seed})
  5. Worker → Gateway (streaming): token_chunk ({type, job_id, seq, delta})
  6. Worker → Gateway: job_complete ({type, job_id, prompt_tokens, completion_tokens, finish_reason})
  7. Bidirectional: job_cancel ({type, job_id, reason})