Unable to get example to work #36
-
I'm trying to get the first example in the docs to work, but I'm failing. Here's my full code:
This is what I get:
It is my understanding that the variable $openaiClient is called with authentication. So, where am I going wrong? I use an API key that I created an hour before running this code. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hi @MastaBaba, I think these two lines may be the issue: $api_key = "{{key}}"; getenv($api_key) Are you storing your API key in an environment variable? The getenv() PHP function loads the value from the environment variable named I'd encourage you to use an environment variable for your API key. Please see the docs for more details: https://tectalic.com/apis/openai/docs/php#usage Or if you aren't using an environment variable and you are hard-coding it in the PHP code itself, then you would need to remove the I hope that helps, James |
Beta Was this translation helpful? Give feedback.
-
Thanks @om4james. Indeed, I was not familiar with getting environment variables in PHP, so misunderstood this function. I got it working now. |
Beta Was this translation helpful? Give feedback.
-
That's great news @MastaBabal, thank you for letting me know. All the best with your project. James |
Beta Was this translation helpful? Give feedback.
Hi @MastaBaba,
I think these two lines may be the issue:
Are you storing your API key in an environment variable? The getenv() PHP function loads the value from the environment variable named
{{key}}
.I'd encourage you to use an environment variable for your API key.
Please see the docs for more details: https://tectalic.com/apis/openai/docs/php#usage
Or if you aren't using an environment variable and you are hard-coding it in the PHP code itself, then you would need to remove the
getenv()
call.I hope that helps,
James