Full command reference for @closedrouter/cli, HTTP and MCP API reference for https://api.closedrouter.app, and step-by-step Self-Hosted Vault setup for individuals, workspace members, and teams.
Install the official CLI from npm, sign in to your organization workspace, connect accounts (either directly, through the local Claude Code bridge, or through your own Self-Hosted Vault), and launch any supported coding harness against your workspace pool.
Run cr with no arguments to launch the interactive onboarding wizard. It walks through browser sign-in, local credential scanning, and workspace API key setup.
Three ways to add accounts
Method
Where credentials live
Best for
Self-Hosted Vault
Encrypted locally on your laptop, home server, or VPC (/data/vault.db or private Postgres). Never uploaded to ClosedRouter.
Individuals, workspace members, and teams who want zero remote secret storage for OpenAI, Anthropic, Gemini, xAI, or custom OpenAI-compatible API keys.
Local Bridge (cr gateway)
Stays on your laptop inside your local Claude Code login.
Sharing a personal Claude Code subscription while your machine is online without uploading your login.
Direct import (cr import / Dashboard)
Encrypted with AES-256-GCM inside ClosedRouter.
Fastest setup for Codex, GitHub Copilot, Cursor, Antigravity, or API keys when you want hosted failover 24/7 without running a container.
Self-Hosted Vault setup guide
A ClosedRouter Vault is a lightweight multi-arch container (ghcr.io/arterialist/closedrouter-vault:latest, supporting linux/amd64 and linux/arm64) that keeps all provider API keys and OAuth tokens encrypted locally under your own VAULT_MASTER_KEY. It handles local OAuth auto-refresh, model discovery, and 5-hour/weekly quota probing inside your host, and opens an authenticated outbound WebSocket tunnel to https://api.closedrouter.app with zero inbound ports required.
Recommended for individuals and distributed teams. Point cr start or your SDKs at https://api.closedrouter.app/v1. ClosedRouter pools across every teammate's Vault, local Claude Code bridge, and hosted seat with full quota-aware routing and guardrails, then sends requests down the chosen Vault's outbound WebSocket tunnel. Your credentials never leave your host.
Zero prompt egress: Local-direct mode (--vault / vault:8080)
For laptops or VPCs where prompts cannot leave your network. Run cr start claude --vault (or call http://127.0.0.1:8080/v1/... / http://vault.internal:8080/v1/... with a cr-sk-... key). Vault fetches a metadata-only route plan from ClosedRouter (model, pool, and an opaque local session hash, zero prompt text) so quota-window scoring, sticky prompt-cache affinity, named pools, and guardrails still work centrally while Vault calls providers directly.
Strict credential isolation. Both the Vault runtime and the ClosedRouter backend enforce a hard schema boundary: any metadata sync or telemetry frame containing secret fields (api_key, access_token, refresh_token, credentials, password, vault_master_key) or prompt content (messages, prompt, content) is rejected with HTTP 400.
Supported account types: Vault stores API keys (openai_api, anthropic_api, claude_api, gemini_api, google_api, xai_api, plus custom OpenAI-compatible endpoints) and OAuth subscriptions (codex_oauth, copilot_oauth, cursor_oauth, grok_oauth, antigravity_oauth) with automatic local token refresh and quota probing. Claude Code subscriptions (claude_oauth) continue to run through cr gateway alongside your Vault so Claude OAuth stays bound to your local Claude Code CLI.
Fastest setup (CLI + Docker)
Any member of a ClosedRouter workspace can connect their own API keys and local subscriptions through their own Vault node without needing workspace admin permissions. Requires Docker Desktop, OrbStack, Colima, or Docker Engine.
Two-command Vault onboarding
npm install -g @closedrouter/cli
cr login
cr vault up --import
cr vault up --import mints a node token in your active workspace, writes a 0600 env file at ~/.closedrouter/vault.env (reusing your existing keys on later runs so your encrypted SQLite volume stays readable), starts the hardened container, waits for the outbound tunnel to connect, and imports local provider logins and API keys straight into your local Vault with zero cloud secret upload. Pass --private to keep imported accounts restricted to your own requests.
Verify and launch coding harnesses
# Check tunnel health and synced accounts
cr vault doctor
# Pool across your workspace (tunnel-relayed)
cr start claude
# Local-direct mode (zero prompt egress, routes through your local Vault)
cr start claude --vault
cr verify claude --vault
Manual Docker setup (or headless VPS)
Mint a personal Vault node token. Sign in to dashboard.closedrouter.app/accounts, click Connect account, open the Self-hosted Vault tab, enter a node name (for example my-laptop-vault), and click Mint Vault token. You can also mint a token from Workspace -> Self-hosted Vault nodes or from the CLI:
Copy the returned cr-vn-... token once. ClosedRouter stores only its SHA-256 hash.
Start your Vault container. Requires Docker Desktop, OrbStack, Colima, or Docker Engine on macOS, Linux, or Windows. Save VAULT_MASTER_KEY and VAULT_ADMIN_TOKEN locally (for example in a 0600.env file) so your encrypted SQLite volume stays readable across container restarts.
Load accounts locally. Run cr vault import to scan local OAuth logins and API keys automatically, or add explicit API keys inside the container. Accounts are shared with your workspace pool by default; pass --private to restrict an account to only your own requests.
Import local logins or add explicit API keys
# Option A: import local Codex, Copilot, Cursor, Grok, Antigravity, and env keys
cr vault import
# Option B: add an explicit API key inside the container
source ~/.closedrouter/vault.env
docker exec closedrouter-vault closedrouter-vault add \
--admin-token "$VAULT_ADMIN_TOKEN" \
--provider openai_api \
--name my-openai \
--api-key "sk-proj-..."
Verify tunnel health and synced accounts.
Check Vault health and active tunnel
cr vault doctor
When control_plane_connected is true and active_accounts is greater than zero, your accounts immediately appear on Accounts under your user identity. To pull your accounts offline immediately, stop the container or revoke the node via cr vault revoke <node-id> or the Dashboard.
Member permissions: Every workspace member can create their own Vault nodes and rotate or revoke the nodes they created. Synced accounts from a member's Vault always belong to that member. Workspace owners and admins can view, rotate, or revoke any Vault node in the workspace.
For teams and organizations (VPC, Docker Compose, Kubernetes)
Engineering teams run one or more shared Vault containers inside their private VPC or cluster. Applications inside the VPC point their OpenAI, Anthropic, or Gemini SDKs straight at http://vault.internal:8080 for sub-millisecond local routing with zero prompt egress, while remote teammates and CI jobs can route through https://api.closedrouter.app over the outbound tunnel.
Mount a PersistentVolumeClaim at /data (or pass DATABASE_URL pointing to your private PostgreSQL instance) and configure liveness and readiness probes on GET /healthz and GET /readyz. For admin-owned team Vaults, pass --owner-email alice@company.com when adding an account to attribute usage and ownership to a specific workspace member.
Team operational behaviors
Multi-account failover: Add multiple accounts serving the same model inside one Vault. Local-direct requests round-robin across eligible accounts and automatically fail over on HTTP 429 or 5xx upstream errors.
Cross-protocol translation: Call /v1/chat/completions backed by Anthropic or Gemini keys, or call /v1/messages backed by OpenAI keys. Tools, tool calls, tool results, streaming SSE, developer role, top_p, stop, and response_format are preserved.
Zero-downtime reconnects: During ClosedRouter backend blue-green deployments, active Vault tunnels receive WebSocket close code 1001 and reconnect automatically with jittered backoff.
Instant kill switch: Running cr vault revoke <node-id> or clicking Revoke in the Dashboard closes the live tunnel with close code 1008 and disables all synced accounts immediately.
Vault container CLI, local API, providers, and environment
Command (closedrouter-vault)
Description
doctor
Checks /health and /local/status, reporting tunnel connectivity, node ID, workspace ID, and active account count. Exits non-zero if disconnected.
status
Prints tunnel state, control-plane URL, active accounts, and last tunnel error.
list
Lists local Vault accounts (metadata only, never secrets).
sync
Forces an immediate metadata sync with ClosedRouter.
Encrypts and stores a provider account locally and syncs metadata. Optional flags: --access-token, --base-url, --owner-email, --private.
rotate <ref> --api-key <new-key>
Re-encrypts credentials for an existing local account ref without changing its ID or model mappings.
remove <ref>
Deletes an account locally and deactivates its synced metadata on ClosedRouter.
Variable
Required
Purpose
VAULT_MASTER_KEY
Yes
32-byte hex secret used to derive AES-256-GCM encryption keys for local credentials. Never leaves your host.
VAULT_ADMIN_TOKEN
Yes (prod)
Protects /local/* account management endpoints via X-Vault-Admin-Token.
VAULT_NODE_TOKEN
Yes
Workspace registration token (cr-vn-...) minted in the Dashboard or via cr vault create.
CONTROL_PLANE_URL
Yes
ClosedRouter API origin: https://api.closedrouter.app.
LOCAL_GATEWAY_URL
No
Internal URL shown in the Dashboard for teammates inside your VPC (default http://127.0.0.1:8080).
DATABASE_URL
No
Optional private PostgreSQL connection URL. Omit to use encrypted SQLite at /data/vault.db.
Supported Vault provider types:openai_api, anthropic_api, claude_api, gemini_api, google_api, xai_api, plus custom OpenAI-compatible endpoints via --base-url.
Local HTTP endpoints exposed on port 8080:GET /v1/models, POST /v1/chat/completions, POST /v1/messages, POST /v1/responses, POST /v1beta/models/{model}:generateContent, POST /v1beta/models/{model}:streamGenerateContent, GET /health, GET /healthz, GET /readyz, and admin routes /local/status, /local/sync, /local/accounts, /local/accounts/{ref}/rotate.
CLI reference (@closedrouter/cli)
Install globally with npm install -g @closedrouter/cli. Both cr and closedrouter invoke the same binary. Global option: -s, --server <url> overrides the ClosedRouter API origin (default https://api.closedrouter.app).
Configure how models are grouped in the interactive model picker.
cr update
None
Download and install the newest @closedrouter/cli release immediately.
Launching coding tools (cr start / cr launch)
cr start [tool] [tool-args...] configures environment variables and model selection for a coding CLI or desktop app and launches it against your active ClosedRouter workspace. Forward tool-specific flags after --.
Skip the interactive model picker and launch directly with a specific gateway model ID.
--pool <id>
Pin this launch to a specific named account pool ID or name.
--desktop
Launch the desktop app for codex, claude, cursor, or antigravity.
-k, --key <key>
Use a specific cr-sk-... key instead of the saved CLI key.
--path <path>
Override the path to the installed CLI binary or macOS .app bundle.
--no-verify-model
Skip the startup protocol preflight check on previously verified gateways.
Workspace, pools, and Vault management
Command
Description
cr workspace [id]
Switch the active organization workspace, or list workspaces interactively when omitted.
cr pool [id]
Pin a default named pool for future launches (pass default to reset to the full workspace pool).
cr pool status [--pool <id>] [--json]
Display active seats, current 5-hour and weekly quota consumption, and cooldowns.
cr pool forecast [--pool <id>] [--json]
Forecast remaining weekly capacity and reset times across seats.
cr vault up [name] [--import] [--private] [--port 8080] [--pull]
One-command local Vault bringup: mints a node token, saves 0600 ~/.closedrouter/vault.env, starts the Docker container, waits for tunnel readiness, and optionally imports local logins/keys.
Scan local provider logins and API keys and load them directly into your local Vault with live model and quota probing (zero cloud secret upload).
cr vault doctor (alias status)
Check local Vault health, outbound tunnel connection, and every synced account's models and quota windows.
cr vault down / cr vault logs [-f]
Stop the local Vault container (preserving encrypted data and vault.env) or view container logs.
cr vault list (alias ls)
List registered Self-Hosted Vault nodes in the active workspace with online status and synced account counts.
cr vault create <name> [--local-url <url>]
Mint a one-time cr-vn-... token and print ready-to-use container environment variables. Available to all workspace members.
cr vault rotate <node-id>
Rotate a Vault node's token and disconnect its existing tunnel.
cr vault revoke <node-id>
Revoke a Vault node, terminate its active tunnel immediately, and disable all synced accounts.
Local Claude Code bridge (cr gateway)
Aliases: cr daemon, cr bridge. Keeps your Claude Code subscription login on your own machine while serving workspace requests over an authenticated outbound bridge.
Command
Description
cr gateway
Run the Claude Code bridge in the foreground. Options: -k, --key, --key-stdin, -n, --name, --claude-path.
cr gateway install
Install and start the bridge as a persistent background service (macOS launchd or Linux systemd).
cr gateway status [--json]
Check whether the background bridge service is installed, running, and connected.
cr share (share Mac or Linux desktop), cr share status, cr share stop, cr share grok. Options: --view-only, --virtual-desktop <name>, --resolution <WxH>, --vnc <host:port>.
cr desktop
Manage isolated Linux virtual desktops and run GUI apps on a named desktop.
cr skill & cr agent-status
cr skill [install|uninstall|show] installs the Claude Code skill and pool status hooks; cr agent-status outputs one-line pool and session telemetry.
API reference
Use https://api.closedrouter.app directly for lowest latency, Server-Sent Events streaming, WebSockets, and MCP. Standard HTTP inference routes are also proxied on https://closedrouter.app.
Base URLs and request headers
Protocol
Base URL
Auth header
OpenAI Chat & Responses
https://api.closedrouter.app/v1
Authorization: Bearer cr-sk-...
Anthropic Messages
https://api.closedrouter.app
x-api-key: cr-sk-... or Authorization: Bearer cr-sk-...
Gemini REST
https://api.closedrouter.app/v1beta
x-goog-api-key: cr-sk-...
Streamable HTTP MCP
https://api.closedrouter.app/mcp
OAuth 2.1 PKCE token or Authorization: Bearer cr-sk-...
Local Self-Hosted Vault
http://127.0.0.1:8080 (or VPC URL)
Same cr-sk-... headers on /v1/* and /v1beta/*
Optional routing header: Send X-ClosedRouter-Pool-Id: <pool-uuid> on any inference request to restrict routing to a named workspace pool.
Inference and discovery endpoints
Method & path
Scope
Description
GET /health
Public
Returns JSON health status, version, environment, and database readiness.
GET /v1/models
models
OpenAI-compatible list of models routable by the key across active shared, private, and online Vault accounts.
GET /v1beta/models
models
Gemini-compatible model catalog for the authenticated key.
POST /v1/chat/completions
chat / gateway
OpenAI Chat Completions with SSE streaming, tool calling, vision inputs, and automatic failover across subscriptions, Vaults, and API keys.
POST /v1/responses & WS /v1/responses
responses / gateway
OpenAI Responses API over HTTP SSE or WebSocket (used by Codex CLI, Codex Desktop, and Grok Build). Pass store: false to disable temporary background run storage.
POST /v1/messages
messages / gateway
Anthropic Messages API with typed SSE streaming, prompt caching preservation, and tool use (used by Claude Code and Anthropic SDKs).
POST /v1beta/models/{model}:generateContent
gemini / gateway
Non-streaming Gemini REST generation.
POST /v1beta/models/{model}:streamGenerateContent?alt=sse
User-authenticated Vault node endpoints require a workspace session token or a manage-scoped key. Pass X-ClosedRouter-Workspace-Id: <workspace-uuid> when targeting a specific workspace.
Endpoint
Auth & permissions
Purpose
POST /api/v1/vault-nodes
Any workspace member
Mint a new Vault node and one-time cr-vn-... token. Body: {"name": "my-vault", "local_gateway_url": "http://127.0.0.1:8080"}.
GET /api/v1/vault-nodes
Any workspace member
List active Vault nodes with online status, synced account counts, and per-node can_manage flag.
GET /api/v1/vault-nodes/{id}
Any workspace member
Inspect one Vault node and its synced metadata-only accounts.
POST /api/v1/vault-nodes/{id}/rotate-token
Node creator, admin, or owner
Issue a fresh cr-vn-... token and disconnect any live tunnel using the old token.
DELETE /api/v1/vault-nodes/{id}
Node creator, admin, or owner
Revoke the Vault node, close its tunnel with WebSocket 1008, and deactivate synced accounts.
WSS /api/v1/vault-nodes/tunnel
cr-vn-... token
Outbound persistent WebSocket tunnel used by the Vault container for heartbeats, sync, and relayed inference.
POST /api/v1/vault-nodes/sync
cr-vn-... token
HTTP metadata-only sync endpoint (rejects secret fields with HTTP 400).
POST /api/v1/vault-nodes/validate-key
cr-vn-... token
Validates a workspace cr-sk-... key and returns allowed models and limits (cached 30s locally).
POST /api/v1/vault-nodes/route
cr-vn-... token
Returns a centralized quota-aware candidate order, sticky cache pin, and guardrail decision for Local-Direct traffic (metadata only, rejects prompts).
POST /api/v1/vault-nodes/feedback
cr-vn-... token
Reports upstream 429/5xx cooldowns or 200 recovery from Local-Direct calls into ClosedRouter's central cooldown tracker.
POST /api/v1/vault-nodes/telemetry
cr-vn-... token
Ingests sanitized numeric token and latency counters from local-direct traffic (rejects prompt content with HTTP 400).
MCP, OAuth 2.1, Device Flow, and Autonomous Agent Signup
Connect Claude Code, Cursor, or any MCP-compatible agent directly to ClosedRouter over Streamable HTTP MCP at https://api.closedrouter.app/mcp.
Add ClosedRouter MCP to Claude Code
claude mcp add --transport http closedrouter https://api.closedrouter.app/mcp
POST https://api.closedrouter.app/oauth/device_authorization
Headless terminals or remote servers; a person approves the code at https://dashboard.closedrouter.app/agent-connect.
Autonomous Agent Signup
POST https://api.closedrouter.app/api/v1/agent/signup
Zero-human bootstrap. Send {"name":"my-agent"} to receive an isolated workspace, an immediate cr-sk-... key, and a one-time claim_url.
Invite Link Join
POST https://api.closedrouter.app/api/v1/agent/join
Join an existing workspace with {"invite":"<link>","name":"my-agent"}.
Scopes, errors, rate limits, and versioning
Scope
Access granted
gateway
Model inference across OpenAI, Anthropic, and Gemini endpoints.
models
List routable workspace models via GET /v1/models and GET /v1beta/models.
chat / responses / messages / gemini / images
Individual endpoint-family scopes when restricting a key to one protocol.
vms
Create, inspect, exec commands on, transfer files to, and stop workspace Linux VMs.
board
Read, post, claim tasks, and wait for events on Agent Board threads.
manage
Programmatic workspace key, account, pool, Vault node, and usage management (must be granted explicitly).
Structured JSON errors: Every error returns JSON with error.code, error.type, and error.message (never HTML).
Rate-limit headers: Responses advertise RateLimit-Policy. Quota-exhausted or capped calls return HTTP 429 with Retry-After (seconds until earliest reset) and X-ClosedRouter-Cap (for example quota-5h, quota-weekly, or daily-tokens).
Versioning and sunset: Inference routes are path-versioned (/v1, /v1beta) and emit X-API-Version. Deprecated routes emit RFC 8594 Deprecation and Sunset headers with at least 90 days notice.
Ready to connect your workspace or launch a Vault?
Sign in to mint an API key or a Vault node token, or reach out to support@closedrouter.app if you hit a snag.