Skip to content

feat: add --anthropic-key option for direct Anthropic API access (BYOK)#271

Open
okedeji wants to merge 2 commits intoPostHog:mainfrom
okedeji:feat/byok-anthropic-fallback
Open

feat: add --anthropic-key option for direct Anthropic API access (BYOK)#271
okedeji wants to merge 2 commits intoPostHog:mainfrom
okedeji:feat/byok-anthropic-fallback

Conversation

@okedeji
Copy link

@okedeji okedeji commented Feb 12, 2026

Problem

The wizard is currently blocked for frameworks that rely on the agentic flow (e.g., Next.js App Router). When it tries to call the LLM gateway, the gateway returns 401s (Authentication required), so no Claude calls can be made. OAuth and MCP init succeed, but the wizard can’t progress because it can’t reach the gateway. There’s no fallback path.

...
◇  API error occurred
No chunk id map found
│
└  
❌ API Error

API Error: 401 {"detail":"Authentication required"} · Please run /login
API Error: 401 {"detail":"Authentication required"} · Please run /login
API Error: 401 {"detail":"Authentication required"} · Please run /login

Solution

Add a --anthropic-key CLI flag (and POSTHOG_WIZARD_ANTHROPIC_KEY env var) so users can provide their own Anthropic API key. When this is set, the wizard skips the PostHog LLM gateway and sends Claude requests directly to api.anthropic.com.

Everything else stays the same (OAuth, MCP auth, env tools, post‑agent steps). The gateway is still the default; this is just an escape hatch.

Why this helps

  • The wizard becomes usable for users who want to still explore when the gateway is down
  • Enterprise teams may prefer their own keys for compliance, contractual, or infra reasons. They can be supported without a change of experience
  • This also sets us up nicely when continuous AI interactions are introduced, say vscode extension. Team can later decide whether to subsidize, charge, or encourage BYOK

Usage

CLI flag
npx @posthog/wizard --anthropic-key sk-ant-xxx

Environment variable
POSTHOG_WIZARD_ANTHROPIC_KEY=sk-ant-xxx npx @posthog/wizard

Works with CI mode
npx @posthog/wizard --ci --region us --api-key phx_xxx --anthropic-key sk-ant-xxx --install-dir .

Test plan

  • pnpm build: compiles with zero errors
  • pnpm test: 124 tests pass, 0 failures
  • pnpm fix: 0 lint errors
  • Manual test: wizard completes full Next.js integration via direct Anthropic API
  • Existing behavior unchanged when --anthropic-key is not provided

Image Reference

The error while using the published v1.31.2.

Screenshot 2026-02-09 at 23 21 26

The error while running the latest main to ascertain if it was an already fixed client issue not yet published

Screenshot 2026-02-11 at 15 59 30

The successful run after implementing BYOK

Screenshot 2026-02-12 at 00 23 05

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant