def _get_api_key(self, api_key: str | None = None) -> str:
        """Get the OpenAI API key.

        Attempts to get the API key in the following order:
        1. From the provided argument
        2. From environment variable ``OPENAI_API_KEY``
        3. From ``.env`` file

        Args:
            api_key (str | None, optional): API key provided directly. Defaults to
                ``None``.

        Returns:
            str: Valid OpenAI API key

        Raises:
            ValueError: If no API key is found
        """
        if api_key is None:
            load_dotenv()
            api_key = os.getenv("OPENAI_API_KEY")
        if api_key is None:
            msg = (
                f"OpenAI API key must be provided to use {self.model_name}."
                " Please provide the API key in the constructor, or set the OPENAI_API_KEY environment variable"
                " or in a `.env` file."
            )
            raise ValueError(msg)
        return api_key
Get the OpenAI API key.

        Attempts to get the API key in the following order:
        1. From the provided argument
        2. From environment variable ``OPENAI_API_KEY``
        3. From ``.env`` file

        Args:
            api_key (str | None, optional): API key provided directly. Defaults to
                ``None``.

        Returns:
            str: Valid OpenAI API key

        Raises:
            ValueError: If no API key is found
        
src/anomalib/models/image/vlm_ad/backends/chat_gpt.py