Coverage for codexa/core/env.py: 100%

8 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-08-10 07:53 +0000

1import os 

2 

3from codexa.core.constants import Environment 

4from codexa.core.errors import CodexaEnvironmentError 

5 

6 

7def load_api_key() -> str: 

8 """Load the API key from the environment. 

9 

10 Raises: 

11 CodexaEnvironmentError: If the API key env variable not set 

12 

13 Returns: 

14 str: LLM API key 

15 """ 

16 key = os.environ.get(Environment.API_KEY, None) 

17 if not key: 

18 raise CodexaEnvironmentError( 

19 message=f"{Environment.API_KEY} environment variable is not set", 

20 help_text=f"Set {Environment.API_KEY} and try again", 

21 ) 

22 return key