Tip Accessing API OpenAI Key in 1Password via terminal

Thought I’d share an effective way I use 1Password in my workflow. So I have this python code that calls OpenAI. Instead of creating a .env file to store my OpenAI key, i can access it directly in 1Password, my password manager of choice.

Firstly, make sure you install 1Password CLI.

Next, sure you authenticate 1P in terminal: op signin

To retrieve the API Key securely:

OPENAI_API_KEY=$(op item get "OpenAI API Key" --fields label=api-key)

This assumes you have your key stored as a label titled api-key under an entry titled OpenAI API Key.

I find this an elegant solution and if you need to update the key in 1Password it will reference the updated key in your code.