Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If no API key configured, let users provide one #5

Open
simonw opened this issue Apr 19, 2024 · 2 comments
Open

If no API key configured, let users provide one #5

simonw opened this issue Apr 19, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Contributor

simonw commented Apr 19, 2024

A pattern I like for this is storing the user's API key in localstorage in their browser and sending it each time it's needed - but avoiding storing it on the server or in any log files anywhere, so I don't need to worry that a breach of my application could leak other people's API keys.

I built a simple tool that does that here: https://tools.simonwillison.net/haiku - code here: https://github.com/simonw/tools/blob/baebe5777294e4ecb5a482aca4919be214132024/haiku.html#L139

function getApiKey() {
  let apiKey = localStorage.getItem("ANTHROPIC_API_KEY");
  if (!apiKey) {
    apiKey = prompt("Please enter your Anthropic API key:");
    if (apiKey) {
      localStorage.setItem("ANTHROPIC_API_KEY", apiKey);
    }
  }
  return apiKey;
}
@simonw
Copy link
Contributor Author

simonw commented Apr 19, 2024

Using localstorage could be a simple way to support persisting user's previous image uploads and form generations as well - then there's no need to store anything server-side.

@timpaul timpaul added the enhancement New feature or request label Apr 23, 2024
@timpaul
Copy link
Owner

timpaul commented Apr 23, 2024

Lovely idea - thanks @simonw :-)

@timpaul timpaul added wontfix This will not be worked on and removed wontfix This will not be worked on labels May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants