PrivyTranslate

Desktop Local API · v1

A translation endpoint that never leaves your machine.

The macOS app can expose a REST and WebSocket API bound to 127.0.0.1, so your own scripts and tools can translate through the same local-first pipeline the app uses.

Overview

Enable Local API in PrivyTranslate Settings. The service then listens on the loopback interface only — it is not reachable from another machine, and no request is proxied anywhere.

Base URLhttp://127.0.0.1:49321/v1
API versionv1
PlatformmacOS
Content typeapplication/json

Download OpenAPI JSON

Authentication

Settings displays an API token once the Local API is enabled. Every endpoint except /health and /capabilities requires it. Three transports are accepted:

  • X-Privy-Token header — the primary form for HTTP requests.
  • Authorization: Bearer — accepted by both HTTP requests and the WebSocket handshake.
  • ?token= or ?access_token= — query parameters for browser WebSocket clients, which cannot set headers.

Treat the token like any other credential: it grants translation on your machine to whatever holds it.

Endpoints

Translate

POST /translate takes a batch of up to 128 strings and returns one result per item, in order. source defaults to auto; target is required.

Request

curl
curl -s http://127.0.0.1:49321/v1/translate \
  -H "X-Privy-Token: $PRIVY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "source": "auto",
    "target": "zh-Hans",
    "texts": ["Could you confirm the revised delivery schedule?"],
    "mode": "paragraph",
    "format": "text",
    "options": { "engine": "auto", "sensitive": true }
  }'

mode accepts selection, paragraph, webpage, subtitle, message or document. format accepts text, html or markdown. Under options, engine pins a specific backend (local-llm, ollama, lm-studio, openai-compatible) and sensitive: true keeps the request out of translation history.

Response

200 · application/json
{
  "id": "tr_8F2A6D4E-5F58-4A37-8E92-7B4FD40BE2D2",
  "object": "translation",
  "created": 1755561600,
  "engine": "local-llm",
  "model": "translategemma-4b-it.Q4_K_M.gguf",
  "source": "en",
  "target": "zh-Hans",
  "results": [
    {
      "index": 0,
      "text": "能否确认修订后的交付时间表?",
      "detected_source": "en",
      "confidence": 0.98,
      "alternatives": []
    }
  ],
  "usage": { "input_chars": 48, "output_chars": 15, "latency_ms": 412 }
}

Detect

POST /detect returns a language code and a confidence score between 0 and 1 for each item, without translating it.

curl
curl -s http://127.0.0.1:49321/v1/detect \
  -H "Authorization: Bearer $PRIVY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "texts": ["Guten Morgen", "早上好"] }'
200 · application/json
{
  "id": "det_8F2A6D4E-5F58-4A37-8E92-7B4FD40BE2D2",
  "object": "language_detection",
  "created": 1755561600,
  "results": [
    { "index": 0, "language": "de", "confidence": 0.97 },
    { "index": 1, "language": "zh-Hans", "confidence": 0.99 }
  ],
  "usage": { "input_chars": 16, "latency_ms": 24 }
}

WebSocket

GET /ws/translate upgrades to a WebSocket. Each frame you send is a TranslateRequest; each frame you receive is either a TranslateResponse or an ErrorResponse. Use it when you are translating a stream of short items and want to avoid per-request overhead.

JavaScript
const socket = new WebSocket(
  "ws://127.0.0.1:49321/v1/ws/translate?token=" + PRIVY_TOKEN
);

socket.addEventListener("open", () => {
  socket.send(JSON.stringify({
    target: "ja",
    texts: ["The quarterly invoice is attached."]
  }));
});

socket.addEventListener("message", (event) => {
  const frame = JSON.parse(event.data);
  if (frame.error) console.error(frame.error.message);
  else console.log(frame.results[0].text);
});

Limits and languages

GET /capabilities reports the live values; these are the defaults.

max_items128
max_chars_per_item8000
max_total_chars50000

Language codes

Target languages use BCP 47 codes. source additionally accepts auto.

  • enEnglish
  • zh-Hans简体中文
  • zh-Hant繁體中文
  • ja日本語
  • ko한국어
  • frFrançais
  • deDeutsch
  • esEspañol
  • viTiếng Việt
  • thไทย
  • idBahasa Indonesia
  • msBahasa Melayu
  • filFilipino
  • myမြန်မာ
  • kmខ្មែរ
  • loລາວ

Errors

Failures return a single error object with a stable type.

invalid_request_error 400, 413, 422 Malformed body, unknown field, or a batch over the limits.
authentication_error 401, 403 Missing, wrong or revoked API token.
server_error 500, 503 Translation pipeline failed, or the app is not ready yet.
400 · application/json
{
  "error": {
    "code": "batch_too_large",
    "message": "texts exceeds max_items (128)",
    "type": "invalid_request_error",
    "param": "texts"
  }
}