diff --git a/autogen/oai/openai_utils.py b/autogen/oai/openai_utils.py index e0c4dbbd79..537390109c 100644 --- a/autogen/oai/openai_utils.py +++ b/autogen/oai/openai_utils.py @@ -90,7 +90,7 @@ def is_valid_api_key(api_key: str) -> bool: Returns: bool: A boolean that indicates if input is valid OpenAI API key. """ - api_key_re = re.compile(r"^sk-[A-Za-z0-9]{32,}$") + api_key_re = re.compile(r"^sk-(proj-)?[A-Za-z0-9]{32,}$") return bool(re.fullmatch(api_key_re, api_key)) diff --git a/test/oai/test_utils.py b/test/oai/test_utils.py index 65ec7a014a..8f4dd22145 100755 --- a/test/oai/test_utils.py +++ b/test/oai/test_utils.py @@ -382,6 +382,7 @@ def test_is_valid_api_key(): assert not is_valid_api_key("sk-asajsdjsd22372%23kjdfdfdf2329ffUUDSDS") assert is_valid_api_key("sk-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS") assert is_valid_api_key("sk-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS1212121221212sssXX") + assert is_valid_api_key("sk-proj-asajsdjsd22372X23kjdfdfdf2329ffUUDSDS12121212212") assert is_valid_api_key(MOCK_OPEN_AI_API_KEY)