refactor config API. normalize api key handling