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

Can you change the Open AI API key setup to read the environment variable instead of writing it in the config? #4

Closed
Dakai opened this issue Aug 29, 2023 · 6 comments

Comments

@Dakai
Copy link

Dakai commented Aug 29, 2023

People including me backs up their dot file in Github or other cloud platforms may accidentally expose their API key to the public, which I just did.

@LSleutsky
Copy link

☝🏻 this!

It says in the documentation that you can set the OPENAI_API_KEY environment variable to make this work, but that is not the case, and you in fact need to set the openai_api_key option in the config, which as @Dakai had pointed out, will be exposed if one's Neovim config is pushed to GitHub (which most people's is)...

@Dakai
Copy link
Author

Dakai commented Aug 29, 2023

Hey @LSleutsky , actually, I just found out that it works with OPENAI_API_KEY environment variable when I just delete the openai_api_key option in the config.

@LSleutsky
Copy link

Hmm, really? That's bizarre, it doesn't work for me. Sometimes it gives me an error message that I've exceeded my API billing usage, even tho I have tons of credits on my OpenAI account, and have tried creating new keys and setting it to the env variable you mention, and still nada!

Will try to dig around and see why. Thanks for the reply...!

@b0o
Copy link

b0o commented Aug 29, 2023

Another option if you manage your dotfiles with git is to keep the API keys in a Lua file that's in your .gitignore. Here's how I do it:

https://github.com/b0o/nvim-conf/blob/main/lua/user/private.example.lua

https://github.com/b0o/nvim-conf/blob/fdb2fe5ddefdf0c0edf2bea72757bb893fa9f5d2/lua/user/plugin/wtf.lua#L8

@piersolenski
Copy link
Owner

Just to clarify, wtf.nvim will respect the OPENAI_API_KEY environment variable. The openai_api_key is an alternative way to set your key, and will override the environment variable if present - which is useful for testing or people who don't want to set it via the environment variable. Hope that helps!

@marcelarie
Copy link

Another alternative is to have the key in pass and declare it inside the env var like this:

OPENAI_API_KEY=$(pass show openai-api-key)

on fish shell:

    set -g OPENAI_API_KEY (pass show openai-api-key)

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

No branches or pull requests

5 participants