Overview

A connected subscription runs through a gateway: the one Allternit Desktop runs on the person’s own computer, or the one on their Sessions computer. The Allternit API forwards requests to that gateway and adds the gateway token server-side. Every task that would send something through a subscription needs a human action: proof that a person sent or confirmed that task. Agents, tools, bots and schedules never get one on their own. They prepare the task on an approval card, and the action is created when a person approves it.
This namespace is served by the Allternit API data-plane node (http://127.0.0.1:8013 on the same machine, or your paired or provisioned node), under /api/v1.

Which gateway answers

allternit-api reads ALLTERNIT_LOCAL_SUBS_GATEWAY: ALLTERNIT_LOCAL_SUBS_GATEWAY_PORT (default 7788) and ALLTERNIT_LOCAL_SUBS_GATEWAY_STATE_DIR (its keychain.json holds the gateway token) say where the local gateway is. GET /api/v1/subscriptions/status reports local: true when the local gateway answers, fallback: true when it is Desktop’s, and sessions_computer with the bound computer that is not answering, if any.

The gateway inside Allternit Desktop

surfaces/allternit-desktop/scripts/prepare-subs-gateway.cjs bundles services/subscription-gateway into resources/subs-gateway:
  • src/main.js and one entry per adapter, with shared chunks.
  • Adapter data files, migrations and Playwright.
  • bin/ax-bridge on macOS.
The gateway uses node:sqlite, so no native module ships. Desktop runs it on Electron’s own Node. It is not started where the machine already runs a gateway (ALLTERNIT_LOCAL_SUBS_GATEWAY=1). State lives in ~/.allternit/subscriptions with the file secret store. The script ends by booting the bundle once on a throwaway state dir. With SUBS_GATEWAY_LOCAL_DESKTOP=1, the gateway is on the person’s own computer:
  • Browser lanes are off until PUT /v1/settings/browser-lanes {"enabled": true}. While off, no browser account routes, the web route is offline, GET /v1/providers reports login_supported: false, and a sign-in answers 409 browser_lanes_off.
  • When on, a browser lane starts the installed Google Chrome itself (worker/hidden_chrome.ts) and Playwright attaches over CDP. Chrome runs with --headless=new, on the account’s own profile, with automation features off and Chrome’s normal user agent. Never Chrome for Testing.

Endpoints

Submitting a task

POST /api/v1/subscriptions/gateway/v1/tasks with the action in the x-allternit-human-action header:
The forwarder checks, in order: the body, the provider, the disclosure version, then the human action. The action is used up only when everything passes. It belongs to one user, expires after 10 minutes, and works once; a retry with the same idempotency_key may reuse it. Accepted tasks are stamped with initiated_by: {kind: "human", user_id, action_id}.

Approval cards are bound to their task

When a person approves a subscription card, the action created for it can start only the task on that card. The card carries the task as subscription.task: Submit exactly that task with the action. A task with a different capability, provider, prompt or options is refused with human_action_task_mismatch, and the action is not used up. The card’s preview and provider are taken from subscription.task, so what the person reads is the start of what runs. A card without a complete subscription.task (sent by an Allternit runtime from before task binding) cannot be approved: the decision returns 409 task_required, the card stays open with that message, and the person can reject it and ask again once Allternit has updated.

Route router

A vendor app can be driven over one of six routes, chosen deterministically — the same (vendor, eligible routes, order, override) always picks the same route, and the choice is logged with its reason. Fixed order: android-app → iphone-app-ictrl → desktop-app-cdp → desktop-app-ax → web → iphone-app-usb-agent (phones first — day-one setup with apps the person is already signed into; vision routes last — slowest). A route is eligible only when the vendor is signed in on it, it is online, and it passed every item of the vendor’s capability contract (start/continue a chat, read the streaming reply and its end, stop mid-stream, send attachments, exact text and files out, list/reopen threads, typed usage-limit/sign-out/verification-wall errors). Results are stored per app version: an app update makes a route ineligible until the conformance suite re-runs. A route that misses even one item is not offered — it never quietly does less. Phone routes report eligible: false with their failing items until their adapters (a follow-up task) pass conformance; nothing is assumed. The chosen route is written into the vendor’s binding. Failover to the next eligible route happens only between turns — a turn already streaming never switches. With no eligible route the turn fails typed: NO_ROUTE with a plain reason such as “phone offline, no other signed-in route”. GET /v1/routes answers:
boundRoute and override appear only when set; appVersion and checkedAt only after the suite has run for the current app version. PUT /v1/routes/:vendor/override with { "route": "<id>" | null } pins or clears the override — the pin still has to be eligible, otherwise 400 route_not_eligible. The debug-port route (desktop-app-cdp) is used only while the shipped app accepts its debug flag unmodified; a launch-time probe records which desktop lane applies per app version. Allternit never patches, re-signs or injects into a vendor binary — when the flag is off, the app routes through accessibility (desktop-app-ax) or the phone instead.

Chats from the model picker use the same routes

A chat with a subscription model from the model picker (subs-chatgpt, subs-claude, …) is a POST /v1/tasks with capability chat.create or chat.continue and routing.provider set. At submission — the start of the turn — the gateway asks the same route router a bot turn asks:
  • A phone or desktop-app route (android-app, iphone-app-ictrl, iphone-app-usb-agent, desktop-app-cdp, desktop-app-ax): the turn runs through that route’s adapter, the same calls a bot turn makes. The task reads exactly like any other task: task.status running, reply events with reply.text.delta, then completed with result.text. status_detail names the route (via android-app: …). A later turn in the same thread_id continues the same conversation in the app, also after a gateway restart (table app_route_threads). POST /v1/tasks/:id/cancel presses the app’s Stop button while the reply is running.
  • The web route, or no eligible route: the task takes the browser path as before, and that path records its own reasons when nothing can serve it.
  • A thread that already lives in a web account stays there, because the conversation belongs to that account.
An app-route failure ends the task failed with a typed error. Examples: provider_ui_changed when the app’s layout moved, auth_required, rate_limited, and timeout when the app never finished its reply. These errors have fallback_eligible: true, so the next turn can pick another route. A running turn never switches routes. Turns that a vendor adapter submits on its own were already routed when they started (x-subs-route-chosen: 1 over the gateway’s socket), so they are not routed a second time.

Errors