create api in thread and defensive