A model host is a device that runs a model and serves it to its owner’s agents. Today that is an Allternit browser tab with WebGPU (see Run a model on your phone). The device keeps one WebSocket open to cloud-api; callers use an Chat Completions-compatible surface, and cloud-api forwards each request to the device as a frame. Source: 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 of A-Z a-z 0-9 _ -. The web app keeps a stable random id per browser.
  • name: up to 80 characters, shown as owned_by in the model list. Empty becomes Device.
  • A ticket works once and expires after 60 seconds. It is bound to the user, the host id and the name.
  • ws_url is wss://<public host>/api/v1/model-hosts/connect?ticket=…. The public host is the request’s own host, or ALLTERNIT_MODEL_HOST_WS_BASE when 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:
The id is <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. model must be <host_id>/<model_id> of one of the caller’s online hosts, otherwise 404 {"error": {"message", "type": "model_not_found"}}.
  • cloud-api rewrites model to the bare <model_id> and sends the body to the device in a request frame.
  • stream: true: text/event-stream. Each chunk frame becomes data: <chunk json>, end becomes data: [DONE]. A device error, a disconnect or a 120 s gap becomes data: {"error": {"message"}} followed by data: [DONE].
  • stream false or absent: the chunks are folded into one chat.completion. The content is concatenated, finish_reason is the last one sent, and usage comes from the last chunk that has it. A device error answers 502 host_error; a disconnect answers 502 host_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 cancel frame.

WebSocket frames

All frames are JSON text frames with a type. 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.