cmd/allternit-cloud-api/src/routes/model_hosts.rs.
Routes
All routes are on the cloud API (https://api.allternit.com).
A runtime device token (
allternit_runtime_…, from gizzi login pairing) acts as the device’s owner, so gizzi can use it as the bearer token for the last two routes. gizzi registers them as the provider allternit-devices (“Your devices”) with base URL <cloud>/api/v1/model-hosts/v1.
Every route only sees the caller’s own hosts. Another user’s host id answers exactly like a host that is offline.
Tickets
host_id: 1 to 64 characters ofA-Z a-z 0-9 _ -. The web app keeps a stable random id per browser.name: up to 80 characters, shown asowned_byin the model list. Empty becomesDevice.- A ticket works once and expires after 60 seconds. It is bound to the user, the host id and the name.
ws_urliswss://<public host>/api/v1/model-hosts/connect?ticket=…. The public host is the request’s own host, orALLTERNIT_MODEL_HOST_WS_BASEwhen set.- A user can have at most 8 hosts online at once (409 when a ticket would add a ninth). Reconnecting an existing host id does not count.
Model ids
The model list returns one entry per model of each online host:<host_id>/<model_id>. With nothing online the list is empty, never an error.
Chat completions
- The body is an standard Chat Completions request, at most 1 MB.
modelmust be<host_id>/<model_id>of one of the caller’s online hosts, otherwise 404{"error": {"message", "type": "model_not_found"}}. - cloud-api rewrites
modelto the bare<model_id>and sends the body to the device in arequestframe. stream: true:text/event-stream. Eachchunkframe becomesdata: <chunk json>,endbecomesdata: [DONE]. A deviceerror, a disconnect or a 120 s gap becomesdata: {"error": {"message"}}followed bydata: [DONE].streamfalse or absent: the chunks are folded into onechat.completion. The content is concatenated,finish_reasonis the last one sent, andusagecomes from the last chunk that has it. A deviceerroranswers 502host_error; a disconnect answers 502host_disconnected.- No first frame from the device within 120 seconds: 504
timeout. - When the caller disconnects before the answer ends, cloud-api sends the device a
cancelframe.
WebSocket frames
All frames are JSON text frames with atype.
Device to cloud:
Cloud to device:
Model ids are 1 to 64 characters of
A-Z a-z 0-9 . _ : - (no /); invalid or repeated entries are dropped, and a host can list up to 16 models.
Connections
- One connection per user and host id. A new connection for the same host replaces the old one: the old socket is closed and its in-flight requests end with an error.
- When a device disconnects, its in-flight requests end with an error and it leaves the model list.
- Everything is held in memory on the cloud-api instance, like the runtime relay. Nothing is written to the database, and prompts and answers are not stored.