English | 简体中文
A local-only unified Rust model gateway and loopback observability console.
Loom routes OpenAI Chat Completions and Anthropic Messages traffic through a single loopback daemon (127.0.0.1:4319) while keeping upstream provider API keys on local disk (0600 files inside a 0700 data directory). Agents only reference a local hub entry key (hub.key). Built entirely in Rust (edition = "2024", Rust 1.89+), Loom requires no Python or Node.js to install, run, or auto-start.
Loom is strictly scoped to model routing, local client synchronization, and loopback request/session observability:
- Loopback-only surface: The inference gateway binds to
127.0.0.1:4319and the management console binds to127.0.0.1:4320. - No silent fallbacks or retries: Different billing channels are never mixed, requests never fall back across providers, and generation is never retried automatically.
- Explicit non-goals: Loom does not include a vendor quota dashboard, account usage scraping, browser extensions, or agent auto-approval/permission-bypass launchers.
- Compatibility naming: The project, repository (
xdlkc/loom), and primary binary are named Loom (loom), whilemodelhubis retained as a command symlink alias alongside thehub/client provider prefix, default port4319, and defaultModelHubdata directories so existing agents and key paths continue working without migration breakage.
Building from source requires the Rust toolchain (and a C compiler such as Xcode Command Line Tools on macOS or cc on Linux for bundled SQLite). When running ./setup.sh interactively without cargo, the script offers guided installation via official rustup.
./setup.sh # Checks compiler/Rust, builds release binary, configures autostart, and builds macOS Loom.app
loom # Launches the interactive terminal control center (status, keys, diagnostics, web/app launch)Once installed, beginners can configure providers and inspect traffic from any of three unified frontends:
- macOS Desktop App (
~/Applications/Loom.app): Native menu bar⌘status icon and standaloneWKWebViewconsole window—start/stop the daemon, jump to provider setup, or run diagnostics without typing terminal commands. - Web Workspace (
loom console): Guided 3-step onboarding wizard with preset vendor cards, official API key links, pitfall tips, one-click connectivity tests, and automatic client synchronization. - Interactive CLI (
loom): Runningloomwith no arguments opens a menu-driven control center alongsideloom add(hidden prompt) andloom doctor --ping.
Existing provider entries and key files are always preserved when reinstalling or upgrading.
cargo build --release --locked
./target/release/loom init
./target/release/loom add
./target/release/loom serveloom install # Installs binary to ~/.local/bin/{loom,modelhub} and registers user autostart
loom install --no-start # Deploys files and service unit without touching a running service
loom app # Builds and opens native macOS ~/Applications/Loom.app (--build-only / --rebuild / --app-dir)
loom doctor --ping # Checks permissions, client sync state, and runs safe 1-token upstream connectivity tests
loom update # Clones main from github.com/xdlkc/loom, builds --release --locked, verifies keys unchanged, and restartsThe installer uses macOS launchctl (~/Library/LaunchAgents/local.model-access.hub.plist) or Linux systemctl --user (~/.config/systemd/user/local.model-access.hub.service) under label local.model-access.hub without root privileges. Before overwriting, binaries, unit files, and configs are backed up privately; if health checks fail, Loom attempts rollback to the prior version. loom update builds inside <data-dir>/updates/ under an exclusive lockfile (update.lock) without modifying your local Git checkout.
Use loom add (alias loom configure) to add preset providers or rotate keys via hidden prompt input (--custom adds unlisted HTTPS endpoints):
loom add # Interactive selection (all presets by default)
loom add zenmux deepseek # Prompt only for selected presets
loom add kimi # Rotate key on an existing preset (Enter to keep current key)
loom add longcat # Configure Meituan LongCat with hidden Open Platform key input
loom add --custom # Configure a custom HTTPS OpenAI/Anthropic provider| # | Preset ID | Provider | Required Credential | Default / Bundled Models |
|---|---|---|---|---|
| 1 | zenmux |
ZenMux | Inference API Key (not Management Key) | Claude 5.5 series (claude-sonnet-5.5, claude-opus-5.5, claude-haiku-5.5) + bundled meta/muse-wonder-1.0, inclusionai/ling-3.1-flash, xiaomi/mimo-v2.6-flash, xiaomi/mimo-v2.6-pro |
| 2 | glm |
GLM Coding Plan | Coding Plan API Key | glm-5.3, glm-5.3-flash, glm-5.3-flashx, glm-5.2, glm-5.1, glm-5-turbo, glm-5, glm-4.7, glm-4.6, glm-4.5, glm-4.5-air |
| 3 | minimax |
MiniMax Subscription | Subscription Key | MiniMax-M3.1-Flash |
| 4 | deepseek |
DeepSeek API Wallet | Open Platform API Key | deepseek-flash, deepseek-v4-pro |
| 5 | kimi |
Kimi Code Subscription | Kimi Code API Key (not Moonshot Open Platform Key) | k3.1-pro, k3.1-pro-highspeed, k3, k3-256k, kimi-for-coding, kimi-for-coding-highspeed |
| 6 | longcat |
LongCat Open Platform | LongCat API Key (not web session token) | LongCat-2.5 |
Preset references: ZenMux, GLM Coding Plan, MiniMax, DeepSeek, Kimi Code, and LongCat. Preset defaults use 128000 context window and 8192 max output tokens unless overridden in providers.json or the bundled catalogs.
Loom embeds catalog/zenmux.json, catalog/glm.json, and catalog/kimi.json at compile time:
- Existing providers matching those official
baseURLendpoints automatically receive newly bundled models at runtime without modifying your privateproviders.jsonor key files. - Machines without a configured provider will not auto-create one.
- Local entries with the same
idalways take precedence (preserving custom names, context/output limits, and"enabled": falseoverrides). - Set
"includeBundledModels": falseon a provider to opt out of runtime catalog supplementation completely.
- OpenAI Base URL:
http://127.0.0.1:4319/v1(POST /v1/chat/completions) - Anthropic Base URL:
http://127.0.0.1:4319(POST /v1/messages) - Model Directory:
GET /v1/models(returns Anthropic-native model list format when Anthropic headers such asanthropic-versionorx-api-keyare present; OpenAI list format otherwise) - Health Check:
GET /health(unauthenticated loopback probe returning{"ok":true,"service":"local-model-hub","runtime":"rust"}) - Gateway Authentication: Local hub key (
hub.key) viaAuthorization: Bearer <hub-key>;/v1/messagesalso acceptsx-api-key, rejecting conflicting credentials (401). - Model Routing: Request models by central ID such as
zenmux/anthropic/claude-sonnet-5.5(clients underhubresolvehub/<provider>/<model>).
- Byte-for-byte streaming passthrough: SSE chunks, reasoning fields, tool calls, images, cache hints, and vendor fields are forwarded untouched;
max_tokens(ormax_completion_tokens) is clamped to the model's configuredmaxTokensceiling. Request bodies are capped at20 MiB(30sread timeout), responses at64 MiB, and concurrent in-flight inference requests at8semaphore permits (429 LOCAL_CONCURRENCY_LIMIT). - Native Anthropic routes: Mapped automatically for ZenMux (
https://zenmux.ai/api/anthropic), GLM (https://open.bigmodel.cn/api/anthropic,https://api.z.ai/api/anthropic), MiniMax (https://api.minimax.cn/anthropic,.minimaxi.com,.minimax.io), DeepSeek (https://api.deepseek.com/anthropic), Kimi Code (https://api.kimi.com/coding), and LongCat (https://api.longcat.chat/anthropic, using Bearer authentication per upstream requirement), or customanthropicBaseURL. - Upstream
402explanations: Returns HTTP402(UPSTREAM_402) with safe, whitelisted category hints (subscription_quota_exhausted,insufficient_credit, orpayment_required) without leaking raw upstream prose. - Upstream TLS uses the system trust store and the bundled Mozilla WebPKI roots for inference and provider connectivity checks. If the system store cannot be loaded, Loom still uses the bundled roots to verify certificates and hostnames. If your network uses a corporate CA, add it to the system trust store and restart the Loom service.
loom doctorreports how many system roots the CLI loaded. When set in the Loom process,SSL_CERT_FILEorSSL_CERT_DIRoverrides the default source of system roots. - Transport
502diagnostics: Returns HTTP502(UPSTREAM_UNAVAILABLE) classified into fixed categories (timeout,request_invalid,tls_error,dns_error,connect_failed,transport_failed) without exposing upstream URLs or credentials.
loom console # Opens http://loom.localhost:4320/ with a one-use login ticket
loom console --page providers # Opens a specific section (onboarding / providers / integrations / overview / requests / sessions / settings)
loom console --host 127.0.0.1 # Fallback host if browser does not resolve *.localhostThe management console listens separately on 127.0.0.1:4320 (configurable via --admin-port on loom serve). loom console (and macOS Loom.app) exchanges hub.key over POST /api/launch (blocked if Origin is present) for a 60-second single-use ticket, exchanged for an 8-hour HttpOnly; SameSite=Strict session cookie (loom_console). Seven integrated views cover the full lifecycle:
- Onboarding Wizard: Automatically opens on fresh installs when no active models are configured; guides users through 6 preset vendors and custom HTTPS endpoints with official key links, pitfall tips, and live connectivity tests.
- Providers Manager: Enable/disable providers, rotate API keys without echoing old credentials, toggle bundled public model catalogs, enable/disable or add/remove individual models, and run safe 1-token upstream probes with whitelisted error diagnostics.
- Integrations & Network: Inspect and trigger sync for
pi,OpenCode V2, andClaude Code, copy generic OpenAI/Anthropic base URLs (never displayinghub.keycontents), and configure or disable the persistent loopback outbound HTTP/HTTPS proxy. - Overview: Filter by time window (
24h/7d/30d), provider, model, and harness; view input/output token curves, cache read/write breakdown, token-weighted cache hit rate, average TTFT, P50/P95 latency, and success/error counts. Unknown usage stays unknown (—), reasoning tokens are never double-counted into output totals, and vendor wallet balances are never fabricated. - Requests: Inspect stage timings (
authenticated,routed,dispatch, headers, TTFT, completion), sanitized client request payloads, forwarded payloads (credentials excluded), full response/SSE logs, and jump to linked sessions. - Sessions Workspace: Three-column replay & waterfall workspace backed by a read-only background worker polling every 15 seconds for native transcripts in
~/.pi/agent/sessions,~/.claude/projects, and~/.local/share/opencode/opencode.db(supporting both OpenCode V2session_v2/session_messageand V1message/partschemas). Native imports are linked deterministically via session headers (x-loom-harness,x-loom-session-idfrom integrations/pi.ts and integrations/opencode2.ts) or Claude Code metadata/response IDs—never guessed by prompt similarity and never double-counted into gateway metrics. - Capture Settings: Independently toggle request/response body capture and native session import, and configure retention (
1–3650days, default30days).
Observations are stored locally in <data-dir>/observability/traces.sqlite3 (0600 inside 0700) with secret/token redaction applied prior to persistence and a 16 MiB per-response capture cap (truncated: true if exceeded). See docs/observability.md for the specification and metrics rules, and prototypes/session-workspace/README.md for the synthetic frontend session-workspace prototype.
Default data directory locations (override via --data-dir <path> or MODEL_HUB_DATA_DIR):
- macOS:
~/Library/Application Support/ModelHub/.local - Linux:
~/.local/share/ModelHub/.local
Example providers.json:
{
"proxy": "",
"providers": {
"local-demo": {
"prefix": "demo",
"name": "My provider",
"baseURL": "https://provider.example/v1",
"anthropicBaseURL": "https://provider.example/anthropic",
"billing": "API Wallet",
"enabled": true,
"keyFile": "/absolute/path/to/local/key",
"models": [
{
"id": "model-id",
"name": "Model",
"contextWindow": 128000,
"maxTokens": 8192,
"input": ["text"],
"reasoning": true
}
]
}
}
}loom proxy # Show current mode (direct or persistent proxy configured)
loom proxy http://127.0.0.1:7890 # Set persistent HTTP/HTTPS proxy (takes effect on next request)
loom proxy off # Restore direct upstream connections
loom set-key local-demo # Rotate upstream API key via hidden input (backs up old key)
loom check # Validate providers.json and confirm every keyFile existsLoom explicitly builds upstream clients with .no_proxy() and ignores terminal HTTP_PROXY / HTTPS_PROXY environment variables so background autostart services behave identically regardless of shell environment. loom proxy rejects URLs containing embedded usernames, passwords, query strings, fragments, non-root paths, or non-HTTP(S) schemes, and never echoes the full proxy URL.
Running loom sync (or updating providers.json while loom serve watches it every 2 seconds) safely updates client configs with private backups under <data-dir>/backups/:
- pi (
~/.pi/agent/models.json,~/.pi/agent/settings.json) and observability extension~/.pi/agent/extensions/loom-observability.ts(integrations/pi.ts, usingbefore_provider_headers). - OpenCode V2 (
~/.config/opencode/opencode.json, or comment-free~/.config/opencode/opencode.jsonc; refuses to overwrite ifopencode.jsonchas comments or both files exist) and plugin~/.config/opencode/plugins/loom-observability/index.ts(integrations/opencode2.ts, usingctx.session.hook("http.request")). - Claude Code (
~/.claude/settings.json, updated only if it already exists, preserving themes, permissions, and unrelated OAuth/providers).
Because clients connect only to 127.0.0.1, URL-based vendor detection inside client SDKs cannot recognize DeepSeek or LongCat behind the gateway. loom sync detects the actual upstream host from providers.json and emits explicit client capabilities:
- DeepSeek (
api.deepseek.com): Setscompat.thinkingFormat: "deepseek"andthinkingLevelMap(minimal -> low,low -> low,medium/high/xhigh -> high,max -> max) forpi, and emitscapabilities.reasoningobject plusnone/low/high/maxvariants(thinking.type: "disabled"vs"enabled") for OpenCode V2 without overriding user defaults. CustompiCompatand model-levelcompat/thinkingLevelMapremain supported. - LongCat (
api.longcat.chat): Preset configurespiCompat: {"thinkingFormat": "deepseek", "supportsReasoningEffort": false}sopitogglesthinking.type(enabled/disabled) without sending unsupportedreasoning_effort.
Run the optional real pi-ai SDK loopback verification (uses a local mock server, no real keys or upstream calls):
node tests/pi-thinking.mjs target/debug/loom /path/to/@earendil-works/pi-ai- Permissions: Private data directories are enforced at
0700;hub.key,providers.json, upstream key files, backups, andobservability/traces.sqlite3are written atomically with0600(PRAGMA journal_mode=DELETE; PRAGMA secure_delete=ON). - Host & Origin isolation:
- Gateway (
4319) enforces loopbackHost(127.0.0.1:4319/localhost:4319) and rejects browserOriginandsec-fetch-site: cross-siterequests exceptchrome-extension://andmoz-extension://origins carrying the localhub.key. - Console (
4320) enforces exactHost(loom.localhost:4320,localhost:4320,127.0.0.1:4320), strict same-originOrigin == http://<Host>, no CORS headers, strict CSP (default-src 'self'; script-src 'self'; ...), andX-Frame-Options: DENY.
- Gateway (
- Upstream validation: Only
https://URLs without credentials, query parameters, or fragments are accepted; HTTP redirects are disabled (Policy::none()). Upstream keys are never written to client configs, telemetry databases, or terminal output.
cargo test --locked
cargo fmt --check
cargo clippy --locked -- -D warningsIn the local tool ecosystem, Loom serves as the unified loopback model gateway for applications such as verba, gloss, and llm-texas-holdem.