Pairs with: Governance REST API (the CLI is a thin shell over it; both call into the same service-layer functions) and Governance MCP server (same surface for agent invocation). Distinct from
langwatch ingest …: that namespace is for debugging ingestion sources; langwatch governance … is for managing every governance resource.Agentic-first by design. Per
specs/ai-gateway/governance/governance-api-cli-mcp-coverage.feature, every governance feature exposes the full CRUD verb set under langwatch governance <resource> <verb>. The CLI is built so a customer can fully set up governance via an agent (Claude Code, Codex, Cursor) without ever opening the dashboard, useful for self-hosted onboarding scripts, CI/CD pipelines, and runbook automations.Why a langwatch governance … namespace
LangWatch already has top-level CLI commands for trace ingestion (langwatch ingest …), projects (langwatch projects …), and login (langwatch login). Governance gets its own namespace because:
- Discoverability:
langwatch governance --helplists every governance resource as a sub-command, so an agent (or a human) can enumerate the surface without prior knowledge. - No collision: top-level resource names like
members,invites,sessionswould overlap with non-governance concepts in a flat layout. Namespacing keeps them unambiguous. - One mental model: every governance verb sits under one prefix; once you know
langwatch governance anomaly-rules list, you know the shape of every command in the namespace.
Availability
Per-account governance entitlement is enforced server-side: if your account doesn’t have governance enabled,governance commands return a clear error pointing you at your admin.
Help discovery
typescript-sdk/src/cli/commands/governance/ and typescript-sdk/src/cli/index.ts (Lane-B at ed51b0ea1).
Authentication
The CLI uses the sameapiKey resolution as langwatch projects list, once you’ve signed in via langwatch login your session lives at ~/.langwatch/sessions/<endpoint>.json, and every governance command authenticates with that session’s apiKey automatically.
governance:read only), list succeeds but create, update, delete exits non-zero with a FORBIDDEN error message naming the missing scope.
Output formats
--json in scripts and CI; the human table is for interactive exploration.
Resource × verb matrix (v1 preview)
The first preview ships with the two governance resources Sergey wired through Hono REST + service-layer + repository (Ask B-1 through B-7). Additional resources fold into the samelangwatch governance <resource> <verb> namespace as the umbrella spec’s coverage extends.
Resources expected to fold into the same namespace as their REST surfaces ship:
anomaly-rules, audit-log, gateway-budgets, ingestion-sources, members, invites, role-bindings, ai-tool-entries, sessions, virtual-keys. The CLI is built so adding a new resource is a commands/governance/<resource>.ts file plus a governanceCmd.command(...) wiring in typescript-sdk/src/cli/index.ts.
Audit emission
Every state-changing CLI invocation emits an audit row withAuditLog.metadata.surface = "cli". The CLI is a REST shell, it calls /api/governance/* and sends the X-LangWatch-Surface: cli request header. The Hono backend’s resolveSurfaceFromRequest helper reads the header, validates it against the GovernanceCallSurface enum (in-process spoofing of trpc, mcp is rejected at the enum filter), and threads the value into the service-layer surface parameter Sergey wired at fc6d54100. The payload shape is identical to a Hono REST audit row apart from the surface field.
The header-validating Hono helper + the 7 mutation call-sites switching from hardcoded 'hono' to resolveSurfaceFromRequest(req) ship in Lane-B’s CLI scaffold at ed51b0ea1. The X-LangWatch-Surface: cli constant lives at typescript-sdk/src/cli/utils/governance/surface.ts.
Setup-from-scratch via agent (v1 preview)
The end-state, what the umbrella spec calls the “agentic dogfood gate”, is that an agent can fully configure governance for a fresh org by chaining CLI commands. The v1 preview ships the IngestionTemplate authoring + ingestion-key mint slice; budgets, anomaly-rules, audit-log fold in as their CLI surfaces ship.~/.langwatch/sessions/<endpoint>.json per-endpoint session resolution handles both transparently.
Cross-references
- Governance REST API: the API the CLI shells over
- Governance MCP server: same surface for agent, MCP-client invocation
langwatch ingest …: separate namespace for ingestion-source debugging- Roles and permissions: RBAC scopes the CLI enforces
- Audit log: where state-change rows land
- Spec,
specs/ai-gateway/governance/governance-api-cli-mcp-coverage.feature