Skip to content

Implement Anthropic API key flow for Assistant#3696

Open
nightnei wants to merge 2 commits into
trunkfrom
addAnthropicApiFlow
Open

Implement Anthropic API key flow for Assistant#3696
nightnei wants to merge 2 commits into
trunkfrom
addAnthropicApiFlow

Conversation

@nightnei
Copy link
Copy Markdown
Contributor

@nightnei nightnei commented Jun 4, 2026

Related issues

How AI was used in this PR

AI was almost useless and just misleading.
I investigated it myself and came up with the approach. AI just followed my instructions and double-checked them.

Proposed Changes

The issue: In Assistant tab of Studio, when we select API key - nothing happens.
Screenshot 2026-06-04 at 15 02 09

The reason: we are using password function from '@inquirer/prompts', to request the Anthropic API key in terminal. It doesn't work for UI, since it's intended to be used only for command line.

What I did: Inverted the password collection dependency by injecting a collectPassword callback through the adapter interface, so each environment (terminal, Desktop UI) owns its own collection strategy instead of the provider hardcoding an interactive TTY prompt.

Testing Instructions

  1. npm run cli:build
  2. node apps/cli/dist/cli/main.mjs code
  3. Select api key and provide yours
  4. Assert that no regresion, it work well as before
  5. npm start
  6. Open Assistant tab
  7. Open ~/.studio/cli.json
  8. Remove aiProvider and anthropicApiKey, since they we added while testing terminal above
  9. Say hi to Assistant
  10. Select API key
  11. Assert that you see the input to provide your password
  12. Fill in your password
  13. Assert that now the API key flow works

Known issues - this PR doesn't cover the case when incorrect API key was provided. First of all this PR is already pretty big, I want to keep it focused on the specific initial issue. And handling incorrect APi key deserves own PR, as I have no idea why errors are printed in Assistant and disappear almost immediatelly from UI. I will create separate Linear issue for it.
Also, I will think more about it, but maybe the best way is introducing /api-key, so that we have aligned way with studio code in the terminal.

@nightnei nightnei requested review from a team, sejas and youknowriad June 4, 2026 14:19
@wpmobilebot
Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing 19cd6da vs trunk

app-size

Metric trunk 19cd6da Diff Change
App Size (Mac) 1332.82 MB 1332.79 MB 0.02 MB ⚪ 0.0%

site-editor

Metric trunk 19cd6da Diff Change
load 1630 ms 1646 ms +16 ms ⚪ 0.0%

site-startup

Metric trunk 19cd6da Diff Change
siteCreation 9032 ms 9001 ms 31 ms ⚪ 0.0%
siteStartup 4427 ms 4414 ms 13 ms ⚪ 0.0%

Results are median values from multiple test runs.

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

@youknowriad
Copy link
Copy Markdown
Contributor

Can we instead disable the "api key" provider entirely from Studio App and rely full on the .com provider? Alternative would be to surface the API KEY config in the app settings but I'm not sure it's necessary for a start. I think there's not much value for the moment to provide your own API KEY specially if we're still giving free access.

@nightnei
Copy link
Copy Markdown
Contributor Author

nightnei commented Jun 4, 2026

Can we instead disable the "api key" provider entirely from Studio App and rely full on the .com provider? Alternative would be to surface the API KEY config in the app settings but I'm not sure it's necessary for a start. I think there's not much value for the moment to provide your own API KEY specially if we're still giving free access.

@youknowriad do you mean to:

  1. Remove this:
    Screenshot 2026-06-04 at 21 07 55

  2. If the user opens the Assistant tab and if aiProvider is not set yet, then set it to wpcom automatically in cli.json

Do I understand your suggestion correctly?

I think it doesn't make sense to show only 1 open to chose, like this:
Screenshot 2026-06-04 at 21 12 39

Copy link
Copy Markdown
Member

@sejas sejas left a comment

Choose a reason for hiding this comment

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

Vova, thanks for working to add Anthropic API. I tested it and confirmed I was able to add my Anthropic API key and worked as expected.

In the testing instructions there is a small typo with the Studio home folder. The folder is hidden and requires a dot Open ~/.studio/cli.json.

Before After
api-key-before.mp4
enter-anthropic-api-key.mp4

I agree with Riad and we can default to WPcom provider without asking the user, at least initially.

@youknowriad
Copy link
Copy Markdown
Contributor

youknowriad commented Jun 5, 2026

Yes, that was my suggestion, I'm hesitant about proposing the removal of the anthropic provider entirely from the the code command as well. (CLI). I think it's still useful for me to check whether an issue is due to our proxy or not, but other than that, I don't see it being useful to users right now.

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.

4 participants