generate api function at run-time