I'm trying to use the OpenAI library (https://github.com/orhanerday/open-ai) which uses environment variables for key storage, but when I run it it doesn't seem to be able to find the key.
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 when I run the following command on the server I see the correct key value printed back to me: printenv OPENAI_API_KEY
In my script I use $open_ai_key = getenv('OPENAI_API_KEY');
but I don't get any value..??
Any information on how to resolve this issue would be greatly appreciated. Thanks!
P粉7041966972024-01-07 09:34:58
Thank you for using orhanerday/OpenAI PHP SDK,
Let’s try setting the “OPENAI_API_KEY” environment variable through the control panel
Select "New..." from the "User Variables" section (top). Add your name/key-value pair, replacing it 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 application, you should get the value.