add hosts create function, and move the api function to a global