@@ -121,53 +121,6 @@ def get_user_id(api_key: Optional[str] = None) -> Optional[str]:
121121 return None
122122
123123
124- def validate_api_key () -> None :
125- """Validate the API key by making a request to the /cfapi/cli-get-user endpoint.
126-
127- Raises SystemExit if the API key is invalid (403) or missing.
128- This should be called early in the CLI flow before starting optimization.
129- """
130- logger .debug ("validate_api_key: Starting API key validation" )
131- api_key = get_codeflash_api_key ()
132-
133- response = make_cfapi_request (
134- endpoint = "/cli-get-user" ,
135- method = "GET" ,
136- extra_headers = {"cli_version" : __version__ },
137- api_key = api_key ,
138- suppress_errors = True ,
139- )
140-
141- if response .status_code == 403 :
142- error_message = "Invalid API key"
143- try :
144- json_response = response .json ()
145- if "error" in json_response :
146- error_message = json_response ["error" ]
147- elif "message" in json_response :
148- error_message = json_response ["message" ]
149- except (ValueError , TypeError ):
150- error_message = response .text or "Invalid API key"
151-
152- msg = (
153- f"Invalid Codeflash API key. { error_message } \n "
154- "You can generate a valid API key at https://app.codeflash.ai/app/apikeys,\n "
155- "then set it as a CODEFLASH_API_KEY environment variable."
156- )
157- logger .error (f"validate_api_key: API key validation failed with 403 - { error_message } " )
158- exit_with_message (msg , error_on_exit = True )
159-
160- if response .status_code != 200 :
161- msg = (
162- f"Failed to validate API key (status { response .status_code } : { response .reason } )\n "
163- "Please check your API key at https://app.codeflash.ai/app/apikeys"
164- )
165- logger .error (f"validate_api_key: API key validation failed with status { response .status_code } " )
166- exit_with_message (msg , error_on_exit = True )
167-
168- logger .debug ("validate_api_key: API key validation successful" )
169-
170-
171124def suggest_changes (
172125 owner : str ,
173126 repo : str ,
0 commit comments