AAnvio
Security

Authentication

Anvio has two independent auth layers — model API keys for the local runtime, and vendor OAuth for external runtimes — plus optional platform login.

4 min read

Anvio runs with no login by default. workspace/anvio.yaml ships with auth.enabled: false, and local tools (filesystem, local browser, local memory, local sessions) work without any credential at all.

Anvio has two unrelated authentication systems that are easy to conflate. Keep them separate:

  1. Model provider API keys (this page, "direct model access") — power the built-in local runtime.
  2. Runtime OAuth (see Runtime OAuth) — powers vendor CLI subscriptions (Claude Code, Cursor, Codex, Antigravity) via anvio setup-token.

A third, optional layer — platform login (JWT/OAuth2 for the API/gateway) — is described below and is unrelated to both.

Layer 1 — Model provider API keys (local runtime)

The default runtime (local) calls model providers directly using API keys, optionally pooled and rotated via encrypted credential pools (packages/credentials). This is the simplest layer: set ANTHROPIC_API_KEY (or any of the 18+ supported provider keys) and the local runtime uses it directly, or acquires one from a pool.

export ANTHROPIC_API_KEY=sk-ant-...
anvio chat

No key at all still works — Anvio drops into mock mode. See Environment Variables for the full key catalog, and Secrets & Encryption for how pooled credentials are encrypted at rest.

Layer 2 — Runtime OAuth (vendor CLI subscriptions)

Per ADR 0009, external runtime providers (claude-code, cursor, codex, antigravity) authenticate through the vendor's own official CLI/app OAuth or session — not through an Anvio-managed API key. This lets an agent run on a Pro/Max/ChatGPT subscription instead of billing API credits.

anvio setup-token --claude    # wraps official `claude setup-token`
anvio setup-token --cursor    # wraps official `agent login`
anvio setup-token --codex     # wraps official `codex login`
anvio setup-token --antigravity
anvio setup-token --list      # show supported vendors

Anthropic policy prohibits third-party products from hosting their own claude.ai login UI or reselling subscription rate limits, so Anvio never implements its own OAuth screen for Claude — it delegates login to the official Claude Code CLI and only stores the resulting token locally, encrypted, in the connection broker.

# Agent binding
spec:
  runtime:
    provider: claude-code
    fallback: local
  model:
    provider: anthropic   # used only when fallback reaches `local`
    model: claude-sonnet-4-20250514

Full detail — auth resolution order, per-vendor mechanics, Docker/headless patterns, multi-user setup — lives on the dedicated Runtime OAuth page.

Never pass ANTHROPIC_API_KEY into the Claude Agent SDK subprocess environment when OAuth mode is active. An API key shadows OAuth and silently switches billing from subscription quota to pay-per-token API credits.

Layer 3 — Platform login (optional, API/gateway)

A third, separate concern: whether the Anvio API/gateway itself requires a login to accept requests. This is controlled by workspace/anvio.yaml:

spec:
  auth:
    enabled: true
    provider: oauth2

Supported provider values, implemented in packages/auth/src/index.ts:

ProviderClassBehavior
none (default)NoAuthProviderNo login, no registration — every request resolves to a default local user (local-user) with the user role. This is what makes auth.enabled: false viable at Level 1–2.
jwtJwtAuthProviderVerifies a JWT signed with JWT_SECRET, extracting sub (userId), email, and roles from the payload. Falls through to null (unauthenticated) on any verification failure.
oauth2OAuth2AuthProviderStub. authenticate() throws 'OAuth2 auth requires provider-specific token exchange (Phase 2+)' — this provider is not fully implemented yet.
// packages/auth/src/index.ts — createAuthProvider()
export function createAuthProvider(
  config: AuthConfig,
  options?: { jwtSecret?: string; defaultUserId?: string },
): AuthProvider {
  if (!config.enabled) return new NoAuthProvider(defaultUserId);
  switch (config.provider) {
    case 'jwt': return new JwtAuthProvider(options?.jwtSecret ?? 'dev-secret', defaultUserId);
    case 'oauth2': return new OAuth2AuthProvider(defaultUserId);
    default: return new NoAuthProvider(defaultUserId);
  }
}

TODO: OAuth2AuthProvider.authenticate() is a stub that throws on every call — treat provider: oauth2 for platform login as not production-ready. This is unrelated to the vendor "runtime OAuth" described above, which is fully implemented for Claude Code/Cursor/Codex/Antigravity.

Enable platform login only when you need it — for example, to gate MCP OAuth flows for GitHub, Google, or Slack behind a real user identity. Most Level 1–2 workspaces never touch this setting.

JWT configuration

JWT_SECRET=change-me-in-production

The JwtAuthProvider defaults to 'dev-secret' if no secret is supplied — always override this in any environment beyond local development.

Choosing what applies to you

You want to...Set
Run anvio chat locally, no billing at allNothing — mock mode
Use Claude/GPT/Gemini directly, pay per tokenModel provider API key (Layer 1)
Use your Claude Pro/Max or ChatGPT subscription instead of API billinganvio setup-token --claude / --codex (Layer 2)
Require login before the API/gateway accepts any requestauth.enabled: true + provider: jwt (Layer 3)
Edit on GitHub

Last updated on

On this page