Is there any api to analyze pagespeed using YSlow?. Currently, I automated yslow with phantomjs but it sometimes taking long time and responding awkward.
Google Pagespeed Insights API
No, there is no hosted YSlow service that would be accessible by an API like that.
In addition to Google Pagespeed, there are other hosted web performance tools you could investigate such as WebPagetest.