weirdnet-openai
A loopback-only OpenAI-compatible bridge over a
weirdnet-agent 0.4 inference Pool. Local tools
that speak the OpenAI API (editors, notebooks, curl) reach the user's inference nodes
through it.
| Route | |
|---|---|
POST /v1/chat/completions |
streaming (SSE, data: [DONE]) or not; reasoning as reasoning_content; tool calls; usage |
GET /v1/models |
the pool catalog, with weirdnet: {state, purpose, replicas, context, revision} |
POST /v1/completions |
a raw prompt (one per request), streaming or not; usage; 501 from nodes that can't take raw prompts |
POST /v1/embeddings |
float vectors; usage.prompt_tokens from the node |
GET /metrics |
Prometheus: weirdnet_bridge_{requests,errors,cache_hits,standin}_total |
Security: it binds 127.0.0.1 only, checks the Host header against its own address (DNS
rebinding), requires a bearer token of at least 16 characters (new_token() makes one;
compared in constant time) and sends no CORS headers, so web pages can't call it.
Headers: x-weirdnet-model (the model that answered), x-weirdnet-cache: hit and
x-weirdnet-standin: <model> when the pool says so. Send x-wait: 1 to wait for the requested
model instead of a stand-in. Non-streaming answers also carry
weirdnet: {standin, cache_hit, served_by}; streams carry it on the final chunk. A stream's
headers are sent once a node accepted the request and sent its early metadata or first output
(at most EARLY_META_WAIT, 1.5 s, later), so x-weirdnet-cache: hit is on streams too; from
nodes before weirdnet-agent 0.4.1 the cache flag arrives only in the final chunk.
use Arc;
use ;
let token = new_token; // show it to the user once; keep it in their keychain
let bridge = bind.await?;
bridge.serve.await?;
Requests map onto infer/2: messages (string content or text parts; other parts are refused
with 400), temperature, top_p, top_k, min_p, max_tokens/max_completion_tokens,
stop, presence_penalty, frequency_penalty, repeat_penalty/repetition_penalty,
seed, response_format (text, json_object, json_schema) and function tools.
continue_final_message: true (vLLM's parameter) continues the last assistant message: the
reply holds only the new text, and a pool with no node that can continue answers 501. Other
parameters are ignored. Dropping a response cancels the pool request.