The city-state, which later became part of Xinjiang), may have been known to its inhabitants by the Tocharian name Agni, which was rendered Yanqi in Chinese sources.
After the conquest of the city of Turfan, center of the kingdom of Gaochang, the Chinese army stationed nearby was seen as a direct threat.
Karasahr ended its tributary relationship with the Tang dynasty and formed a marriage alliance with the Western Turkic Khaganate, its previous suzerain.
Fearing Tang military ambitions, Kucha also ended its status as a Chinese tributary state.
The Tang emperor responded by sending an army led by commander Guo Xiaoke, protectorate-general of the Anxi Protectorate, against the kingdom.
The people of Karasahr then installed Long Lipozhun's cousin Xue Apo'anazhi as their king and remained vassals of the Western Turks.