LOCUStechnical wiki

For apps and scripts

The OpenAI-style /v1 address of your computer

Locus serves an OpenAI-style /v1 address on your computer's Locus address, so an app or a script you trust can use your models from anywhere, the way the Locus app does: over HTTPS, with a device key. The examples are for a Unix shell (macOS, Linux, or Git Bash and WSL on Windows) with curl and openssl.

On the computer itself, a script can also simply use the AI tool's own address (LM Studio's http://127.0.0.1:1234/v1, for example), without Locus.

What it serves

RequestAnswer
GET /v1/modelsThe models a request may name: the loaded models of the default AI tool (the one new chats get, set with locus use)
POST /v1/chat/completions
POST /v1/completions
POST /v1/embeddings
Passed to the default AI tool; a stream is passed on as it comes (30 minutes at most)
Any other /v1/…, /v1/responses included404 not served here

Get a device key

A script is a device: it pairs like a phone, with a one-time code made on the computer, and gets its own key. Give it no right to add or remove devices.

  1. On the computer (on Windows, with the full path of locus.cmd):
    locus pair --no-browser --no-manage
    It prints code XXXX-XXXX-XXXX. The code works once, for 5 minutes.
  2. Exchange the code for a key (the --pinnedpubkey value is explained below):
    curl --insecure --pinnedpubkey "sha256//<pin>" \
      -H "Content-Type: application/json" \
      -d '{"code": "XXXX-XXXX-XXXX", "device_name": "my script", "platform": "cli"}' \
      https://<your-locus-address>/api/pair
    The answer (201) holds "key", "device_id" and "manage": false. The key is shown only in this answer and kept on the computer only as its SHA-256: store it like a password.
  3. The script now shows in locus devices list; locus devices revoke <id> signs it out at once.

Refusals: 401 when the code is wrong, expired or used; 404 when no code is open; 409 when 20 devices are paired already; 429 after too many wrong codes.

Check the computer's certificate

On Windows, your computer serves its own certificate: made for Locus, not from a public authority, and it does not name your address. The Locus app trusts exactly that certificate, by the fingerprint the pairing QR carries. A script must do the same, or anyone in the middle could read its key. With curl, save the certificate once and pin its public key:

openssl s_client -connect <your-locus-address>:443 -servername <your-locus-address> </dev/null 2>/dev/null \
  | openssl x509 -outform PEM > locus.pem
openssl x509 -in locus.pem -noout -fingerprint -sha256
openssl x509 -in locus.pem -pubkey -noout | openssl pkey -pubin -outform DER \
  | openssl dgst -sha256 -binary | openssl base64

The second line prints the certificate's SHA-256 fingerprint: the same value as the pc= part of the link in your pairing QR, there in lower case and without colons. The last line prints the <pin> for curl. Fetching the certificate the first time trusts what the network gives you at that moment, so do it once, from a network you trust. Then --insecure turns off curl's usual checks (which a certificate of its own cannot pass) and --pinnedpubkey accepts your computer's key and no other.

Use the Locus address also from the computer itself: Locus's local port takes only the relay's connections.

Example

curl --insecure --pinnedpubkey "sha256//<pin>" \
  -H "Authorization: Bearer <your device key>" \
  https://<your-locus-address>/v1/models

curl --insecure --pinnedpubkey "sha256//<pin>" \
  -H "Authorization: Bearer <your device key>" \
  -H "Content-Type: application/json" \
  -d '{"model": "<a loaded model id>", "messages": [{"role": "user", "content": "Hello"}], "stream": false}' \
  https://<your-locus-address>/v1/chat/completions

Spoken answers (Windows)

Once the voice is installed on the computer (locus voice get), the chat page asks the computer to read a stored answer aloud; the phone only plays the sound. These routes are on the same Locus address and take the same device key. They are served only when Locus runs on Windows. An App Review device gets 403 review_only on each of them.

RequestBodyAnswer
GET /api/statusAdds "speak": {"state": "absent" | "ready" | "starting" | "failed", …}; absent means not installed (the page then shows no Listen); with a voice installed, voices ([{"id", "lang", "name"}]) and defaults
POST /api/speak{"chat": "<chat id>", "index": <the answer's place in the chat>}, and optionally "voice", "voices" (8 at most) and "speed" (0.7 to 1.4, in tenths); 4 KB at most200 {"job", "parts", "lang": "en" | "fr", "voice", "starting"}
GET /api/speak/<job>/<n>200 audio/wav (16-bit mono PCM, 24 kHz), not cached; waits up to 30 s for the part
DELETE /api/speak/<job>200 {"stopped": true}

The voice settings in an answer

When the chat page sends a message, it may add the phone's own voice settings, "voice": {"aloud", "speed", "voices"}. The computer may then offer the model one more tool, voice_settings (read_aloud, voice, speed), which changes these settings and nothing else. Its checked change comes back in the answer's event stream as the event voice ({"aloud"?, "voice"?, "speed"?}), and the page keeps it on the phone; the computer keeps nothing. The tool is offered only when a voice is installed, never to an App Review device, and only when the chat already uses tools (shared folders or Web) or the message speaks of the voice and the AI tool is known to take tools (LM Studio, or an Ollama model that lists "tools").

On the computer

The admin port (127.0.0.1:8745, for the locus command, with its token) has POST /voice/stop: it stops the voice runner if it runs, and locus voice rm asks it first. Its /status says "voice": {"state", "words", "running", "threads"}.