I am trying to use OpenAI's API to play with some of the examples they have. However, when I go to load my API key, I get errors. I created a ".env" file and did:
OPENAI_API_KEY=XYZ-123
and then in Python I have the following:
import os
import openai
openai.api_key_path = ".env"
openai.api_key = os.getenv("OPENAI_API_KEY")
print(openai.Model.list())
Every time it tells me my API key is malformed. I can also remove the 3rd line and I get the same error that it is malformed but I copied it directly into the .env file from the website. Also, if I set the key directly in Python, it seems to work just fine:
openai.api_key = "XYZ-123"
But for security, I would prefer I don't see the key in my Python code. Any suggestions on how to resolve this?