implemented key error check for every API call