Overview

The Files Drive API runs on the computer that owns the files. This page covers the part that runs in cloud-api at https://api.allternit.com. It decides when a computer may be woken, lists how to reach a computer, keeps the last storage report, and answers browsing from a saved snapshot while the computer sleeps. The rule behind all of it: browsing never wakes a computer and never resets its idle timer. Only an explicit wake consent call wakes one.
These routes ship dark. Each one answers 403 feature_disabled unless the account’s files_drive flag is on (ALLTERNIT_FILES_DRIVE_ENABLED, or the user in ALLTERNIT_FILES_DRIVE_USER_IDS, or an admin) and migration 143 is applied. The no-wake rule for relayed Files requests is always on, flag or not.

Computer ids

Every route takes {id}, which is one of these: An id the caller does not own answers 404 not_found. After the first call, use computer_id from the endpoints response.

Endpoints

All of them need a signed-in session, or an API key with the compute scope, for the owner. The iPhone’s Files extension has no session, so it uses the compute key the app creates for it (“Files on (device)”). The same ownership checks apply either way. A key without compute gets 403, and another user’s computer gets 404.

Transports

endpoints lists how to reach the computer, lowest priority first:
  • A cloud computer (host: cloud_computer) lists one relay candidate, the proxy at /api/v1/runtime-devices/{computer_id}/proxy. Cloud computers never join the mesh.
  • A runtime device on your own machine (host: own_device) lists the relay too.
  • A machine paired by pairing code lists one mesh candidate at http://{mesh_ip}:8013/api/v1/files/v2 and no relay.
computer_state is awake when the computer has a relay connection, waking while a cloud computer starts, asleep for a stopped cloud computer, and offline for your own machine when it is not connected. Content requests (content, manifest, chunks, uploads, writes and content search) to a sleeping computer answer 409 wake_consent_required with a wake hint:
The client asks the user (or skips the prompt when the setting is auto) and calls the consent path:
The answer holds a wake ticket that lasts 120 seconds. Send it on every request of that transfer in the X-Allternit-Wake-Ticket header. A request with a valid ticket waits up to 30 seconds for the computer to come up, then answers 503 waking with a Retry-After header.
  • One ticket wakes the computer at most once. Calling consent again with the same ticket in X-Allternit-Wake-Ticket returns the same ticket and wakes nothing.
  • The consent call records exactly one activity touch, so the idle sweep does not put the computer back to sleep at once. Files traffic records none.
  • A ticket works only for its own user and computer. An expired ticket answers 409 wake_consent_required; another user’s or another computer’s ticket answers 403 forbidden.
  • Setting never answers 403 wake_denied. A machine that cloud-api cannot wake answers 503 offline. A spend cap or hours limit answers with that reason.

Browsing a sleeping computer

While a computer has no relay connection, the relay answers these from its asleep snapshot, with freshness.served_by: "snapshot" and freshness.computer_state: "asleep": With no snapshot yet, these answer 503 asleep. Other metadata (trash, versions, comments) answers 503 asleep too. The live change-feed socket is not offered for a sleeping computer: the socket ticket answers 503, and clients poll changes instead. Permissions on snapshot items come from the root’s policy. execute is always false. The runtime checks everything again once the computer is awake.

How the snapshot gets there

The runtime writes its snapshot through cloud-api while it is awake, signed like the presence heartbeat (x-allternit-runtime-id, x-allternit-runtime-ts, x-allternit-runtime-sig): cloud-api stores them in the user’s own file storage under files-snapshots/{computer_id}/v1/. It drops protected roots and path_hint from the manifest, and refuses a root file for a root the stored manifest does not list, so Memory Drive names never reach storage. A manifest for another computer is refused. Write the manifest first, then each root. allternit-api writes the snapshot by itself:
  • When. On the sleep notice and at most every 5 minutes while changes are pending. The sleep notice is SIGTERM, which a cloud computer being stopped or Desktop quitting sends, and the write gets a 5 s budget. ALLTERNIT_FILES_SNAPSHOT_EVERY_S sets the interval (default 300, at least 60).
  • What. Plain names, sizes and revisions of every root that isn’t protected. Never contents, local paths or path_hint.
  • Only changes. The manifest goes out only when a root or a cursor changed. After it, only the root files whose cursor moved go out. An unchanged drive sends nothing. A root that cloud-api didn’t store is sent again on the next pass.

Storage discovery

The runtime adds a filesStorage block (a StorageDiscovery) to its presence heartbeat, POST /api/v1/runtime-presence/heartbeat. cloud-api keeps the last one per computer and serves it at GET /api/v1/computer-files/{id}/storage, also while the computer sleeps. The report is always stored under the signing runtime’s own id. A heartbeat never counts as activity.

Replicas

Placement

GET /api/v1/computer-files/{id}/placement?root_id= suggests where to keep a replica of one root. It ranks the owner’s other computers that sent a storage report. The rules are fixed and explainable, no model picks the device, and the user confirms the pick: Options come best first, and each has a one-sentence reason the picker shows. Ineligible options come last with score: 0. The source computer and other users’ computers are never options.

Peer relay

A cloud computer is reachable only through the relay, so it can’t be pushed to over the mesh. To make one a replica host, register the replica on the source computer without host_base_url. The source then pushes through cloud-api: The caller is a runtime, authenticated with its own device token. The host must belong to the same user. No other path goes through: anything but these replica host routes answers 403. cloud-api forwards only while the host is already connected. It never wakes either computer and never touches either idle timer. An asleep host answers 503 asleep (a computer that isn’t a cloud computer answers 503 offline), and the replica stays behind until both computers are on.

Files key

Replicas are sealed with your Files key, 32 random bytes made on your first device. It never leaves a device unwrapped. cloud-api only keeps each device’s public key and a copy of the Files key sealed to that device (a KeyEnvelope), and it cannot open any of them. The full construction, the confirm code and the vectors are in the contract, contracts/files-drive/SPEC.md section 13. How a device gets the key:
  1. The first device finds no key_id. It makes the key, posts its own request, and grants it to itself. That creates the key. If another first device got there a moment earlier, the grant answers 409 already_exists and this device asks for the key instead.
  2. A new device posts a request and shows its 6-digit code. The code comes from the device’s public key, so it can’t be chosen.
  3. A device that has the key lists the waiting requests and shows each code, worked out again from the request’s public key. You click Approve when it matches the code on the new device. The approving device seals the key to the new device and posts the grant.
  4. A computer gets the key the same way, from your app: the app reads the computer’s request (GET /api/v1/files/v2/replicas/key on the computer), approves it, and hands the computer its envelope with PUT /replicas/key.
cloud-api accepts a grant only for a waiting, unexpired request with the same code, from a device that holds the current key (or, for the first key, from the requesting device itself), and only once. Requests are limited to 20 an hour per account and 5 waiting devices at a time (429 rate_limited). Two waiting devices never show the same code. Every grant, refused grant, rotation and removal is written to the audit log (files_key.*). Removing a device (DELETE …/devices/{id}, or revoking a computer) deletes its envelopes and sets rotation_needed. The next device that has the key makes a new one, seals it to every device still listed, and posts a KeyRotation. A rotation that leaves a device out, or includes the removed one, answers 409 rev_mismatch. The old key’s envelopes stay, so replicas sealed with it still open until they are sealed again. Removing the last device that holds the key retires it, and the next device starts a new one. Reading a replica while the computer sleeps. The client asks placement for your other computers, works out the replica id for each awake one, and reads the sealed head, catalog and chunks from it over the relay. It checks every chunk and the whole file against their hashes before showing anything. The replica host never reads them.
These routes answer 403 feature_disabled until migration 145 is applied and the owner’s files_drive flag is on. They need a signed-in session or a compute key, like the other owner routes.

Protected-root unlock

Protected roots (Memory Drive, and any root with policy.protected) need a fresh unlock on the device. Right after the local check passes (Face ID, Touch ID or fingerprint on a phone, a click on the web), the app asks cloud-api for a short-lived token:
  • Who. The owner’s session only, and only for a computer the owner has. device_id is the app’s own X-Allternit-Device-Id.
  • Token. fut1. + base64url claims + . + base64url Ed25519 signature over fut1. and the claims part. The claims are {v: 1, typ: "files_unlock", user_id, device_id, computer_id, iat, exp, kid}, and exp is 300 seconds after iat. It is signed with the same key as wake tickets and guest tokens, so the runtime checks it offline with GET /api/v1/computer-files/token-keys.
  • Use. The app keeps the token until expires_at and sends it as X-Allternit-Unlock (also over the relay). After that, it asks for the local check again.
  • Limits. At most 30 tokens per user every 10 minutes (429 rate_limited). Each token writes an audit_log row, files.unlock.issued. A computer paired by code only has no runtime id to sign for and answers 409 invalid_request. With no token key configured the route answers 503 key_unavailable.
  • Runtime check. Signature and kid, typ, v, a lifetime of at most 5 minutes, 30 seconds of clock skew, this computer, the signed-in user, and the device when the request names one. Anything else stays 403 protected_root_locked.

Guest drops while a computer sleeps

When a guest drops a file into an upload-only link while the computer sleeps, the sharing gateway keeps it in the owner’s own storage. The computer collects these drops itself once it is awake, about 20 s after its runtime starts and then every 5 minutes (ALLTERNIT_FILES_DROPS_EVERY_S). Each call is signed like its heartbeat, so a computer reads only its own drops: The computer checks each drop’s size and blake3 hash first. A drop that doesn’t match is rejected and never written. A good drop goes into the Inbox as a file from that guest, and becomes an untrusted task that waits for the owner’s approval. Leading dots are removed from the file name. An ack is safe to repeat. The computer remembers which drops it delivered, so a lost ack never makes a second copy. These routes answer 403 feature_disabled until migration 144 is applied and the owner’s flag is on.

Relay details for Files

The relay proxy, POST /api/v1/runtime-devices/{computer_id}/proxy, accepts body_encoding as well as bodyEncoding (utf8 or base64). It passes the request headers x-allternit-wake-ticket, range, if-match, x-allternit-unlock and x-allternit-device-id, and the response headers content-range, accept-ranges and retry-after. It streams the runtime’s response as-is: real status, raw body bytes. Legacy /api/v1/files/* routes still wake a sleeping computer on demand until every client moves to /api/v1/files/v2.