Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save darrenjrobinson/1c0205cb24beb97b4c3c328a89780438 to your computer and use it in GitHub Desktop.
Save darrenjrobinson/1c0205cb24beb97b4c3c328a89780438 to your computer and use it in GitHub Desktop.
Set PowerShellAI OpenAI API Credentials Securely on Windows. Associated blogpost https://blog.darrenjrobinson.com/generative-ai-chatgpt-with-powershell/
# 1. Get API Credential via prompt.
# Only need the password which is your API Key
$gptAPI = Get-Credential
# 2. Export to a file in the local directory
$gptAPI | Export-Clixml ./chatGPTAPIKey.xml
# 3. Ongoing you only need to put the following two lines at the top of your scripts
# Make sure you copy your chatGPTAPIKey.xml file to other directories for scripts for OpenAI.
$chatGPTCred = Import-Clixml .\chatGPTAPIKey.xml
$chatGPTAPIKey = [System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($chatGPTCred.Password))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment