The prefecture (zhou 州) of Tingzhou 庭州 (Türkic name Jimsar) was one of the three prefectures the Tang empire 唐 (618-907) set up in the Western Territories 西域 (the others being Xizhou 西州 and Yizhou 伊州). It included the districts (xian 縣) of Jinman 金滿, Luntai 輪臺, Pulei 蒲類, and later also Xihai 西海. The seat of the prefect was Jinman (present-day Jimsa'r 吉木薩爾).
The region was during the Han period 漢 (206 BCE-220 CE) part of the kingdom of Rear Cheshi 車師後部 and was at the beginning of the 7th century controlled by a Türkish yabghu (Chinese transliteration yehu 葉護), a leader of the Western Türks (Xi Tujue 西突厥). The yabghu submitted to the Tang after their armies had destroyed the kingdom of Gaochang 高昌.
The prefecture of Tingzhou was the northernmost Chinese prefecture in the region and therefore had a great military importance. In order to feed the garrison, military agro-colonies (tuntian 屯田) were set up. In 684 the garrison of Hanhai 瀚海 was manned by 12,000 troops. These were to take control over the Western Türks living north and west of Tingzhou.
In 702, the protectorate (duhufu 都護府) of Beiting 北庭 was set up in Tingzhou, ten years later the protectorate was headed by a military commissioner (jiedushi 節度使) for the region of Yixi 伊西. He had the command over the troops of Hanhai, Tianshan 天山 and Yiwu 伊吾. The large size of the garrison and the importance of Tingzhou as a border market contributed to the economical prosperity of the region.
In 790, Tingzhou was occupied by the Tibetans and in the 850s fell into the hands of the Uyghurs 回鶻. Jimsar became the capital of the five Uyghur cities (Beš Baliq 別失八里).