Fixed API error handling and key deactivation