Skip to content

Validate Anthropic API key in api-key and provider commands in Studio Code CLI - #4504

Merged
sejas merged 2 commits into
trunkfrom
validate-anthropic-api-key-cli
Aug 11, 2026
Merged

Validate Anthropic API key in api-key and provider commands in Studio Code CLI#4504
sejas merged 2 commits into
trunkfrom
validate-anthropic-api-key-cli

Conversation

@sejas

@sejas sejas commented Aug 11, 2026

Copy link
Copy Markdown
Member

Related issues

How AI was used in this PR

AI helped identify and build the code.

Proposed Changes

This PR validates the key at entry time, in both /api-key and /provider (both funnel through the provider's prepare step), and displays an error if the key is not valid.
It only affects CLI. The UI is being implemented in #4503

Testing Instructions

  1. npm run cli:build && node apps/cli/dist/cli/main.mjs code
  2. Run /api-key and enter a made-up key (e.g. fake key): the prompt shows "Anthropic rejected this API key. Check the key and try again." and stays open. Enter a real key: it saves.
  3. Edit ~/.studio/cli.json and corrupt the saved anthropicApiKey, then run /provider and pick "Anthropic · API key": the CLI re-prompts for a key instead of accepting the broken one.
  4. Offline check: disconnect the network and run /api-key with any non-empty key — it saves (unverifiable ≠ invalid).
validate-api-key-when-saving-cli.mp4

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@sejas sejas self-assigned this Aug 11, 2026
@sejas
sejas marked this pull request as ready for review August 11, 2026 12:14
@sejas sejas changed the title CLI: Validate Anthropic API key in api-key and provider commands Validate Anthropic API key in api-key and provider commands in Studio Code CLI Aug 11, 2026

@bcotrim bcotrim left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM 👍

Changing provider doesn't clear the saved key, so we can still boot straight into a dead one — isReady() is just Boolean(anthropicApiKey) (providers.ts:211) and the auto-fallback never calls prepare. Worth validating at boot too, or is the startup round trip too costly? Fine as a follow-up either way.

@bcotrim

bcotrim commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

I've pushed an empty commit to trigger the full CI checks (E2E, Performance tests)

@wpmobilebot

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing 8de6983 vs trunk

app-size

Metric trunk 8de6983 Diff Change
App Size (Mac) 1406.51 MB 1406.29 MB 0.21 MB ⚪ 0.0%

site-editor

Metric trunk 8de6983 Diff Change
load 1070 ms 1044 ms 26 ms ⚪ 0.0%

site-startup

Metric trunk 8de6983 Diff Change
siteCreation 7538 ms 7550 ms +12 ms ⚪ 0.0%
siteStartup 2866 ms 2865 ms 1 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

@sejas
sejas merged commit 7834b4d into trunk Aug 11, 2026
13 checks passed
@sejas
sejas deleted the validate-anthropic-api-key-cli branch August 11, 2026 20:22
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.

3 participants