Skip to content

Wire Protocol

[!NOTE] Pre-release. This protocol may change before v1.0.

Shard A is delivered to the proxy using standard provider authentication headers:

ProviderHeaderPurpose
OpenAIAuthorization: Bearer <shard-A>Shard A for key reconstruction
Anthropicx-api-key: <shard-A>Shard A for key reconstruction

The alias is embedded in the URL path: /<alias>/v1/chat/completions. The proxy extracts the alias from the first path segment and uses it to look up the corresponding shard-B. No custom Worthless-specific headers are required.

PathMethodProviderStatus
/<alias>/v1/chat/completionsPOSTOpenAIStreaming + non-streaming
/<alias>/v1/messagesPOSTAnthropicStreaming + non-streaming
/healthzGETLiveness probe
/readyzGETDB connectivity check

All other paths return 401 (anti-enumeration: unknown endpoints do not return 404).

The proxy returns provider-compatible JSON error bodies so SDKs handle them natively.

StatusMeaningWhen
401Authentication requiredMissing/invalid alias, missing shard-A in auth header, commitment mismatch
402Spend cap exceededCumulative spend exceeds configured cap
429Rate limit exceededRequests per second exceeded (includes Retry-After header)
502Gateway errorUpstream provider unreachable
504Gateway timeoutUpstream provider timed out

All 401 responses return an identical body regardless of failure reason (anti-enumeration).

CodeNameMeaning
WRTLS-100BOOTSTRAP_FAILEDHome directory or database initialization failed
WRTLS-101ENV_NOT_FOUND.env file not found or is a symlink
WRTLS-102KEY_NOT_FOUNDNo API key found, or shard missing
WRTLS-103SHARD_STORAGE_FAILEDFailed to write shard to DB or filesystem
WRTLS-104PROXY_UNREACHABLEProxy failed to start or health check timed out
WRTLS-105LOCK_IN_PROGRESSAnother lock/unlock operation is running
WRTLS-106SCAN_ERRORFile scan failed or invalid scan configuration
WRTLS-107PORT_IN_USEProxy port already bound by another process
WRTLS-108WRAP_CHILD_FAILEDChild process failed to start
WRTLS-199UNKNOWNUnexpected error
VariableDefaultDescription
WORTHLESS_PORT8787Proxy listen port
WORTHLESS_DB_PATH~/.worthless/worthless.dbSQLite database path
WORTHLESS_FERNET_KEY(auto-generated)Fernet key for encrypting Shard B at rest
WORTHLESS_RATE_LIMIT_RPS100.0Default rate limit (requests/second per IP)
WORTHLESS_UPSTREAM_TIMEOUT120.0Non-streaming upstream timeout (seconds)
WORTHLESS_STREAMING_TIMEOUT300.0Streaming upstream timeout (seconds)
WORTHLESS_ALLOW_INSECUREfalseAllow shard-A auth over non-TLS (dev only)
  • Shard A stays on the client machine in .env. It is format-preserving (same prefix, charset, and length as the original key), so the SDK sends it as Authorization: Bearer <shard-A> (OpenAI) or x-api-key: <shard-A> (Anthropic) on every request. The proxy extracts it from the standard auth header. No server-side shard-A storage exists.
  • Shard B is encrypted at rest in SQLite using Fernet (AES-128-CBC + HMAC-SHA256). It is decrypted only in memory during key reconstruction.

The rules engine (rate limiting, spend caps) evaluates every request before Shard B is decrypted. If a rule denies the request, zero key material is touched. This is enforced architecturally — the reconstruction function is only called after all gates pass.

The reconstructed API key is used for the upstream provider call and immediately zeroed. It never appears in any response body, header, or log. The key exists in memory only for the duration of a single HTTP call.

All authentication failures return an identical 401 response body. An attacker cannot distinguish between “alias does not exist” and “shard mismatch” from the response alone. Unknown endpoints also return 401 (not 404) to prevent endpoint discovery.