AuthenticationError: Incorrect API key provided

I am trying to use OpenAI models and build a simple FastAPI. I saved my openai_api_key in .env file. My API is working fine when I run manually without any errors. However, when I built a Docker image of my API and run it as Docker container it shows this error “AuthenticationError: Incorrect API key provided”. I believe my API key is correct because it works when I run API manually “main.py”. Please help me solve this problem

Hi and welcome to the Developer Forum!

You need to make sure your environment variable are set within your docker image, not outside of it.