Early in the "Kaiyuan" era (713-741) of Emperor Xuanzong of Tang, the general Wang Junchuo (王君㚟) served as the jiedushi, a military commissioner, of Hexi (河西, headquartered in Wuwei, Gansu). Niu Xianke and Song Zhen () served as his assistants and were his close associates. In 727 Wang and Song were killed in an ambush by the Uyghur tribal leader Yaoluoge Hushu (), but Niu was able to escape. Subsequently Niu and Pei Kuan () served under the general Xiao Song, the jiedushi of Hexi who replaced Wang. Xiao entrusted much responsibility to Niu, and Niu was said to be honest and hard-working. He began to impress prominent people of the region despite his humble origins. After Xiao became chancellor in 728, Niu was made the secretary general of Liang Prefecture (涼州, roughly modern Wuwei) and acting jiedushi of Hexi through Xiao's recommendation. Xiao continual praise eventually led to Niu's promotion to full jiedushi. While serving as jiedushi, Niu was known to be frugal and saved a large surplus for the governmental treasury, and also had good armor and weapons made.