only save api key when it exists