moved api definition inside try where it belongs