# Repository Briefing: weave-os/router
> Source: https://repoforai.com/repo/weave-os/router (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/weave-os/router
- **Official Docs / Website**: https://weaveos.com/products/router
- **Category**: LLMs & Inference (大模型与推理微调)
- **Primary Language**: Go
- **License**: Apache-2.0
- **Engineering Health**: A (79/100 · Maintenance 35/35 · Adoption 13/25 · Releases 11/20 · License 20/20)
- **Review Snapshot**: 2026-12-04
- **Deployment / Stack Signals**: Docker, Self-Hosted, API, CLI
- **Momentum**: 5,695 ★ total (+14 24h / +79 7d) · 197 forks
- **Topics**: `agentic-coding`, `ai-gateway`, `anthropic`, `claude-code`, `codex`, `model-router`, `openai-compatible`
- **When to Use**: Best for: Teams running coding agents or applications across several model providers that want shared routing, separate provider credentials and centralized usage tracking, and can validate the policy on their own traffic. Skip if: One provider and a fixed model already meet your needs, you need offline inference out of the box, or you expect the self-hosted policy to learn online like the managed service.

## Overview
```text
### Architecture & Core Mechanics
Weave Router is a Go API gateway, not a model-serving runtime. It authenticates clients with `rk_` bearer keys, calls a separate HMM policy sidecar to classify each turn, then selects an enabled model and forwards the request using an environment-provided or BYOK provider key. The sidecar depends on a compatible embedding service and defaults to Google's embedding API.

PostgreSQL holds installation records, router keys, encrypted BYOK credentials and usage data; it also backs the self-hosted dashboard at `/ui`. The Go manifest includes Gin, pgx/v5, Tink and Google Cloud Pub/Sub v2. Multiple replicas need Pub/Sub for cache invalidation, and an optional OTLP collector receives traces and usage logs. Client protocol entrypoints and configurable model endpoints are the main integration boundaries.

### Key Capabilities & Differentiators
The router exposes Anthropic Messages at `/v1/messages`, OpenAI Chat Completions at `/v1/chat/completions`, and Gemini requests at `/v1beta/models/:action`. Upstreams include Anthropic, OpenAI, Gemini, OpenRouter and OpenAI-compatible endpoints. Streaming, tool calls and vision are supported, but test the exact client and upstream pair before assuming feature parity or broader API compatibility.

`POST /v1/route` lets you inspect the policy's choice without dispatching a generation request. Usage reporting, routing-decision exports and session cost tracking support a rollout against a direct-provider baseline. The installer covers Claude Code, Codex, Copilot, opencode and pi, with `--local` available for local setup. Cursor's override applies to Agent and Ask, not Tab completion or Apply; it needs a paid BYOK seat and a URL reachable from Cursor's servers.

### Trade-offs & Limitations
Compared with calling OpenAI directly, Weave centralizes model choice and usage tracking across providers, but adds a proxy hop, policy classification and a database to operate. With a remote embedding service, routing also depends on another network call. If one provider and a static model policy suffice, direct integration has fewer moving parts. For a multi-provider rollout, compare end-to-end latency, cost and task success with your direct baseline rather than using routing-only timing or headline savings as deployment targets.

The self-hosted policy is frozen and lacks the managed service's training, online learning and registry. The Compose stub sends every turn to one routing group, so it validates plumbing, not selection quality. Apache-2.0 covers the router code, not upstream API access. Self-hosting puts router configuration and usage records under your control, but your providers still process generation requests, and Google supplies embeddings by default.

### Hardware & Deployment Guide
The local bootstrap uses Docker, a checkout, Go 1.26 or later and an upstream API key; `go.mod` specifies Go 1.26.0 and toolchain go1.26.10. `make full-setup` starts the router and PostgreSQL and creates a router key. The development Compose stack applies migrations but uses default credentials and a single PostgreSQL instance with no resource limits. Keep it on localhost. Dashboard administration requires `ROUTER_ADMIN_PASSWORD`; requests can still be routed without it.

The default `hmm_embedding` policy needs a sidecar to boot. Compose supplies a smoke stub; `make up-hmm` swaps in the real sidecar for local development, not production. The `hmm-model-v1` release packages `hmm-router-frozen-v1` as a portable frozen policy artifact, with a published SHA-256 and a `google/gemini-embedding-2` contract of 3,072 dimensions. Hosted client setup through `npx @weave-os/router` requires Node 18 or later. Self-hosting does not make the default stack offline: generation and embedding calls still leave it.
```

## Key Capabilities
```text
- Protocol coverage: Anthropic Messages, OpenAI Chat Completions and Gemini request endpoints, with streaming, tool calls and vision support.
- Policy isolation: An embedding-based HMM sidecar classifies each turn; the local smoke-test stub assigns every turn to one group.
- Decision inspection: POST /v1/route reports which model would be selected without sending a generation request to that model.
- Credential separation: Clients use rk_ bearer keys; PostgreSQL tracks installations, usage and encrypted BYOK provider keys.
- Operational dependencies: Optional OTLP export, a self-hosted dashboard at /ui and Pub/Sub cache invalidation for multiple replicas.
- Portable policy artifact: hmm-router-frozen-v1 requires 3,072-dimensional google/gemini-embedding-2 embeddings and ships without Python pickle or training rows.
```

## Quick Start / Clone
```bash
npx @weave-os/router
```
