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
| Request | Answer |
|---|---|
GET /v1/models | The 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/completionsPOST /v1/completionsPOST /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 included | 404 not served here |
- Every request needs
Authorization: Bearer <device key>. - A body is a plain UTF-8 JSON object (no byte-order mark), 32 MB at most, not sent in chunks.
modelmust be the id of a loaded model, as/v1/modelslists it: 404 when unknown, 409 when it is not loaded or still loading./v1never loads a model: load it first, from the phone.- Only
Content-TypeandAcceptare passed on to the tool. Your key never is: Locus sends the tool's own key itself when the tool needs one. - llama.cpp and KoboldCpp started by Locus:
/v1/modelsis answered by Locus (the loaded model, by Locus's id), and only these fields are accepted; any other one is refused with a 400 that names it, never dropped in silence:- chat:
model,messages,stream,stream_options(onlyinclude_usage),max_completion_tokens,max_tokens,temperature,top_p,stop,seed,presence_penalty,frequency_penalty,user,tools,tool_choice,response_format(text,json_objectorjson_schema),reasoning_effort; - completions:
model,prompt(a text or a list of texts),streamand the same sampling fields; - embeddings:
model,input,encoding_format(floatorbase64),user.
n,logit_bias,logprobs,top_logprobs,parallel_tool_callsand every tool-specific field. A message takesrole,content,name,tool_callsandtool_call_id; a part of a message is text orimage_url, and a picture must be adata:URL (Locus never lets the tool fetch an address). A picture for a model started without its image reader gets a 409. - chat:
- LM Studio, Ollama and the other servers get the body as it is.
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.
- On the computer (on Windows, with the full path of
locus.cmd):
It printslocus pair --no-browser --no-managecode XXXX-XXXX-XXXX. The code works once, for 5 minutes. - Exchange the code for a key (the
--pinnedpubkeyvalue is explained below):
The answer (201) holdscurl --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"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. - 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
- 401
missing keyorwrong key; 401this device was signed out on the PC: pair it againfor a revoked key. - 10 wrong keys from one address within 10 minutes block that address for 15 minutes (429, with
Retry-After). - When a device is signed out, a request it is running ends within about a second.
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.
| Request | Body | Answer |
|---|---|---|
GET /api/status | Adds "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 most | 200 {"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 text read is the computer's own stored copy of the answer at that place in the chat, never a text the request
sends. Voice ids:
af_heart,af_bella,bf_emma,am_michael(English),ff_siwis(French). A voice of another language than the answer's is replaced by one ofvoicesin the answer's language, else by that language's default. - Refusals: 409
voice_absent(not installed: "run locus voice get there"); 409nothing_to_read("No voice for this language yet." or "There is nothing to read aloud in this answer."); 400bad_request,bad_voice,bad_speedornot_an_answer; 404no_answerorno_job; 503not_readywithRetry-After: 1(ask again),voice_failedorbusy; 410stoppedorplayed; 409out_of_order; 429waitingortoo_many. - Parts are asked in order, one more than the highest asked so far at most. One job per device (a new one stops the old), 8 jobs on the computer, 60 jobs an hour per device, 20,000 characters a job. Parts live in memory only, never on disk.
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"}.