How to get the value of OPENAI_API_KEY?

Rao, Vinod (CTR) HHHH 5 Reputation points
2023-03-28T17:34:48.69+00:00

I am wondering to set a key for api in the following statement

openai.api_key = os.getenv("OPENAI_API_KEY")

Please let me know where should I find it.

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
2,251 questions
0 comments No comments
{count} vote

3 answers

Sort by: Most helpful
  1. YutongTie-MSFT 46,996 Reputation points
    2023-03-28T18:33:12.78+00:00

    Hello @Rao, Vinod (CTR) HHHH

    Thanks for reaching out to us, you can find the key by going to your resource in the Azure portal. The Endpoint and Keys can be found in the Resource Management section. Copy your endpoint and access key as you'll need both for authenticating your API calls. You can use either KEY1 or KEY2. Always having two keys allows you to securely rotate and regenerate keys without causing a service disruption.Screenshot of the overview UI for an OpenAI Resource in the Azure portal with the endpoint & access keys location circled in red.

    Then you need to create and assign persistent environment variables for your key and endpoint before you run the line - openai.api_key = os.getenv("OPENAI_API_KEY") You need to save it to your Environment variables, please open your command line and run below, replace with your key value -

    setx OPENAI_API_KEY "REPLACE_WITH_YOUR_KEY_VALUE_HERE" 
    

    You can also use PowerShell as below -

    [System.Environment]::SetEnvironmentVariable('OPENAI_API_KEY', 'REPLACE_WITH_YOUR_KEY_VALUE_HERE', 'User')
    

    Please let me know if you need more help, we are happy to help you further.

    Regards,

    Yutong

    -Please kindly accept the answer and vote 'Yes' if you feel helpful to support the community, thanks a lot.

    1 person found this answer helpful.

  2. Travis Wilson 110 Reputation points Microsoft Employee
    2023-03-28T18:32:04.8733333+00:00

    Hello!

    Please check out the Python quickstart for details on retrieving and using your API keys for Azure OpenAI.

    In short, once you've onboarded with Azure OpenAI and created an Azure OpenAI resource, you can copy one of the two keys from the "Keys and Endpoint" pane for the resource in Azure Portal and use that as the value for the environment variable.


  3. Rish Arora 0 Reputation points
    2024-02-16T10:34:15.8933333+00:00

    Hi, FOllowed the same steps and it is still not workig. Used the ENDPOINT API key and yet it says connection issue.

    0 comments No comments