Skip to content
ThinkWatch
Start typing to search the docs.
Core 0.64.0 released→

An AI API gateway engine for desktops and servers

MIT-licensed Rust crates and the twcore binary. twcore is the gateway inside ThinkWatch Lite, and runs on its own as a systemd service on a Linux server, managed from ThinkWatch Lite over an encrypted control channel. ThinkWatch Enterprise uses its format-conversion, guard, circuit-breaker and Bedrock crates.

twcore · the gateway binary Sample
  1. $ twcore init
  2. # write an initial config.yaml and its keys
  3. $ twcore check
  4. # validate the configuration without starting
  5. $ twcore serve
  6. # start the gateway and the control plane
  7. ready gateway 127.0.0.1:8788 · control socket
  8. POST /v1/messages claude-code → anthropic 200 1.2 s
  9. POST /v1/responses codex → chatgpt 429 → relay 200

Capabilities

One binary, the whole gateway.

Rule-based routing

Rules match on the model, the gateway key, the input size, tools, images and other properties of a request, and send it to an upstream or a group, rewrite its parameters or refuse it. When the client and the upstream use different API formats, the request is converted between Anthropic Messages, OpenAI Chat Completions, OpenAI Responses and Gemini.

Failover before the first byte

Until the first byte reaches the client, a failing upstream is replaced by the next one without the client noticing; after that point, the failure is reported. A failing upstream is paused for as long as its reason calls for: an exhausted balance, a used-up quota until its reset, a rate limit for the wait it asks.

$0.0124

Cost accounting

Each request is priced from a public price table, which twcore refreshes daily, or from a price sheet in the configuration, and records where its price came from. Estimated amounts are marked as such, and usage that cannot be priced is labelled unknown.

Outbound redaction

A relay sees every request in full. Credentials in a request can be replaced with placeholders before it leaves, so the relay never holds the real values, and are restored where the answer repeats them.

Malicious tool calls cut off

A relay can rewrite an answer and slip in a tool call for the client to run; a call that downloads and runs code, sends out credentials or does something similar can be cut off mid-stream. A content filter can also delete hidden characters that smuggle in instructions, and all three guards start by only recording.

Encrypted control plane

The desktop app and twcore commands reach core over a local socket, a loopback port on Windows, and an optional remote port. Every control connection starts with a Noise handshake keyed by the control key; no certificates are involved.

Install and deploy

Server deployment

On Linux on x86_64 or aarch64, with glibc 2.35 or newer and systemd, one command installs twcore, a service user and the systemd unit. ThinkWatch Lite on macOS, Windows or Linux then connects to it through the remote control port, and clients anywhere on the network send their requests to its gateway.

On a desktop, twcore comes with ThinkWatch Lite and is not installed separately.

Install on a Linux server

$ curl -fsSL https://raw.githubusercontent.com/ThinkWatchProject/ThinkWatch-Core/main/scripts/install.sh | sudo sh

The server has to run the core version that ThinkWatch Lite requires; the app shows that version when the two differ. To install it:

$ curl -fsSL https://raw.githubusercontent.com/ThinkWatchProject/ThinkWatch-Core/main/scripts/install.sh | sudo sh -s -- --version <version>

Then

  • twcore remote enable --allow 192.168.1.0/24 # open the remote control port to a network
  • sudo systemctl enable --now twcore # start the service
  • twcore control-key # print the key ThinkWatch Lite connects with
  • sudo twcore upgrade --version <version> --restart # later: move to the version ThinkWatch Lite requires, newer or older

Commands that read the configuration run as the service user; the guide describes each step.

sudo -u thinkwatch THINKWATCH_HOME=/var/lib/thinkwatch twcore …

Prebuilt binaries

Every release carries twcore for five targets, each with a SHA-256 file; the Linux archives add the systemd unit. twcore upgrade replaces a standalone installation, while the copy inside ThinkWatch Lite is updated with the app.

Version 0.64.0 · All releases

Build from source

With a stable Rust toolchain, 1.94.1 or newer. The binary is written to target/release/twcore.

  • $ git clone https://github.com/ThinkWatchProject/ThinkWatch-Core.git
  • $ cd ThinkWatch-Core
  • $ cargo build --release -p twcore

Crate layers

  1. Conversion, guards, circuit breaker and Bedrock tw-dialect · tw-guard · tw-breaker · tw-bedrock Also used by ThinkWatch Enterprise
  2. Domain logic tw-types · tw-engine · tw-pricing · tw-yaml · tw-secret · tw-watch
  3. Control-plane contract tw-api · tw-link
  4. Assembly tw-config · tw-store · tw-observe Single-machine implementation
  5. Data plane and control plane tw-gateway · tw-control Single-machine implementation

ThinkWatch Enterprise depends on the first group and nothing else. Those four crates depend only on each other, which a test enforces, and CI builds ThinkWatch Enterprise against every change to them. No crate depends on a group below its own. The last two groups are the single-machine implementation (SQLite, the local control channel and the optional remote port) and are intentionally not shared: single-machine SQLite and multi-tenant Postgres differ too much for one abstraction to serve both.

Crate layers in detail

Development

Testing

The smoke script exercises every path on the real binary from a clean state and reaches the control plane through twcore call. HOME and THINKWATCH_HOME point to a temporary directory that is deleted on completion.

  • cargo test --workspace # unit and integration tests
  • scripts/smoke.sh # every path on the real binary

MIT License

Building on, embedding, and redistributing the crates are permitted.

View on GitHub