Reputation: 26056
I am trying to work with an OpenAI library (https://github.com/orhanerday/open-ai) that uses environment variables for key storage, but it doesn't seem to be finding the key when I run it.
On my local Windows machine I ran the following command: setx OPENAI_API_KEY “mykey”
On the Linux web server I ran the following command: export OPENAI_API_KEY=mykey
Now on the server when I run the following, I see the correct key value printed back to me: printenv OPENAI_API_KEY
In my script I'm using $open_ai_key = getenv('OPENAI_API_KEY');
but I'm getting no value back..??
Any information on how I can resolve this would be greatly appreciated. Thanks!
Upvotes: 1
Views: 1044
Reputation: 1076
Thank you for using orhanerday/OpenAI PHP SDK,
Let's try to set your ‘OPENAI_API_KEY’ Environment Variable through the Control Panel
Select New… from the User variables section(top). Add your name/key-value pair, replacing with your API key.
Variable name: OPENAI_API_KEY
Variable value: <yourkey>
<?php
$open_ai_key = getenv("OPENAI_API_KEY");
print("OPENAI_API_KEY is; $open_ai_key");
$ php index.php
> OPENAI_API_KEY is: sk-gjtv.....
After running the app you should get the value.
Upvotes: 2