@@ -123,17 +123,21 @@ def get_user_id(api_key: Optional[str] = None) -> Optional[str]:
123123
124124def validate_api_key () -> None :
125125 """Validate the API key by making a request to the /cfapi/cli-get-user endpoint.
126-
126+
127127 Raises SystemExit if the API key is invalid (403) or missing.
128128 This should be called early in the CLI flow before starting optimization.
129129 """
130130 logger .debug ("validate_api_key: Starting API key validation" )
131131 api_key = get_codeflash_api_key ()
132-
132+
133133 response = make_cfapi_request (
134- endpoint = "/cli-get-user" , method = "GET" , extra_headers = {"cli_version" : __version__ }, api_key = api_key , suppress_errors = True
134+ endpoint = "/cli-get-user" ,
135+ method = "GET" ,
136+ extra_headers = {"cli_version" : __version__ },
137+ api_key = api_key ,
138+ suppress_errors = True ,
135139 )
136-
140+
137141 if response .status_code == 403 :
138142 error_message = "Invalid API key"
139143 try :
@@ -144,23 +148,23 @@ def validate_api_key() -> None:
144148 error_message = json_response ["message" ]
145149 except (ValueError , TypeError ):
146150 error_message = response .text or "Invalid API key"
147-
151+
148152 msg = (
149153 f"Invalid Codeflash API key. { error_message } \n "
150154 "You can generate a valid API key at https://app.codeflash.ai/app/apikeys,\n "
151155 "then set it as a CODEFLASH_API_KEY environment variable."
152156 )
153157 logger .error (f"validate_api_key: API key validation failed with 403 - { error_message } " )
154158 exit_with_message (msg , error_on_exit = True )
155-
159+
156160 if response .status_code != 200 :
157161 msg = (
158162 f"Failed to validate API key (status { response .status_code } : { response .reason } )\n "
159163 "Please check your API key at https://app.codeflash.ai/app/apikeys"
160164 )
161165 logger .error (f"validate_api_key: API key validation failed with status { response .status_code } " )
162166 exit_with_message (msg , error_on_exit = True )
163-
167+
164168 logger .debug ("validate_api_key: API key validation successful" )
165169
166170
0 commit comments