update library constructor to set the api key if provided