The Guiyi Circuit, or Guiyi Army (歸義軍 Guīyìjūn, 848-1036 AD) was a regional government from the Tang Dynasty to the Northern Song Dynasty. The Zhang family controlled the Guiyi Circuit until the early 10th century, which was followed by the dominance of the Cao family until the 11th century. The seat of the Guiyi Circuit was situated in Shazhou (沙州) (modern Dunhuang).
The Hexi Corridor is an important part of the Silk Road and connects Central Asia with North China. After the Anshi Rebellion, the Hexi Corridor was gradually occupied by the Tibetans (吐蕃). Around the 770s or the 780s, Shazhou, an important city in the Hexi Corridor, was occupied by the Tibetans.
The Zhang family
After some 60 years of Tibetan rule, Tibet entered the Era of Fragmentation in around 842, and Zhang Yichao, a resident of Shazhou Prefecture, led an uprise and got back the city in 848. The Emperor Xuānzong of Tang (唐宣宗) created the Guiyi Circuit and made Zhang Yichao the governor (Guiyi Jiedushi (歸義節度使)) in 851. Zhang kept chasing the Tibetans out of ten nearby prefectures, and the power of the Guiyi Circuit reached its zenith around 861.
Zhang Yichao sent delegations to the royal court to express their submission to the Tang Dynasty. However, the central government of Tang did not trust the Guiyi Circuit. At the beginning Zhang Yitan (張議潭), elder brother of Zhang Yichao, was sent to the royal court as a hostage. In 867, probably because of the death of Zhang Yitan, Zhang Yichao also went to Chang'an, the capital of the Tang, as a hostage, and eventually died there. Zhang Yichao made Zhang Huaishen (張淮深), son of Zhang Yitan, control the Guiyi Circuit. The influence of the Uyghurs (回鶻) became strong in the Hexi Corridor at the time of Zhang Huaishen. During the rule of Zhang Huaishen, the power of the Guiyi Circuit was waning, and its territory was shrinking.
Zhang Huaishen died in 890, and the Guiyi Circuit fell in a chaotic period. No direct records were left about what happened between 890 and 894. What is known is that, Suo Xun (索勳), son-in-law of Zhang Yichao, declared himself as the Jiedushi. Zhang, a daughter of Zhang Yichao, fourteenth in order (張公第十四之女), together with the Li (李) family, the family of her husband, killed Suo Xun. Zhang established her nephew, Zhang Chengfeng (張承奉), also a grandson of Zhang Yichao, as the Jiedushi in 894. There might have been a power struggle between Zhang Chengfeng and the Li family as pointed out by some scholars, the details of which were obscure due to the lack of explicit historic records. Zhang Chengfeng eventually had the real power.
The Ganzhou Uyghur Khanate (甘州回鶻) was getting stronger during the rule of Zhang Chengfeng. The Tang Dynasty also came to its last years at this time. The last two emperors of the Tang Dynasty, Emperor Zhaozong and Emperor of Ai, became puppets of Zhu Quanzhong, founder of the Later Liang. Zhang Chengfeng then declared the establishment of Jinshan State (金山國 Jīnshānguó) and himself "Son of Heaven" (a title for sovereigns). The establishment time of the Jinshan State was not clear, probably around 905 or 910. However, in 911, the Jinshan State was defeated by the Ganzhou Uyghur Khanate. The Great Chancellor (大宰相) and the elders of Jinshan State made a treaty with the Ganzhou Uyghur Khanate, recognizing the superiority of the latter over the former. The relationship between the two was prescribed as
"...the Khan is the father, and the Son of Heaven is the son..." (...可汗是父,天子是子...)
The Khan of the Ganzhou Uyghurs at this time was Tianmu Kehan (天睦可汗). Jinshan State used the Chinese sexagenary cycle to record years and did not have its own era name. The Jinshan State lasted until 914.
The Cao family
Cao Yijin (曹議金) became the ruler in 914. He abolished the Jinshan State and restituted the Guiyi Circuit. Cao Yijin married a daughter of Tianmu Kehan, and with the consent of Tianmu Kehan he sent delegations to the Later Liang. In the 920s, an internal conflict broke out in the Ganzhou Uyghurs. Renmei (仁美), a son of Tianmu Kehan, became the Khan and then followed by another new Khan, his younger brother Diyin (狄銀). Around the same time, Cao Yijin led an expedition to Ganzhou (甘州) and Suzhou (肅州) against the Ganzhou Uyghur Khanate. The expedition was successful, and the Guiyi Circuit regained the access to the rest of China. In 926, Diyin died, and Aduoyu (阿咄欲) became the Khan of the Ganzhou Uyghurs. Aduoyu married a daughter of Cao Yijin. Both the Ganzhou Uyghur Khanate and the Guiyi Circuit sent delegations to the Later Tang in 926, which at the time had replaced the Later Liang.
Cao Yijin died in 935. The power of Guiyi Circuit was transferred to three of his sons, Cao Yuande (曹元德) (ruling 935-939), Cao Yuanshen (曹元深) (ruling 939-944), and Cao Yuanzhong (曹元忠) (ruling 944-974). During this period the Guiyi Circuit had sent delegations to the Later Tang, the Later Jin backed by the Liao Dynasty of the Khitans, the Liao Dynasty, the Later Han, the Later Zhou, and the Northern Song Dynasty.
The Guiyi Circuit was in a relatively stable period under the rule of Cao Yuanzhong. Attention was paid to agriculture, transportation, and culture. Land was distributed to the people. Effort was made to secure the accessibility to and the cultural exchange through the Hexi Corridor. This period was also well known for its block printing craft of Buddhist sutras and illustrations found in Dunhuang. Although small-scaled conflicts happened, the relationship between the Guiyi Circuit and the Ganzhou Uyghur Khanate was relatively good during the rule of Cao Yuanzhong.
After the death of Cao Yuanzhong in 974, Cao Yangong (曹延恭) (ruling 974-976) became the ruler, followed by Cao Yanlu (曹延祿) (ruling 976-1002), both were sons of Cao Yuanzhong. In 1002, a rebellion occurred in the Guiyi Circuit. Cao Zongshou (曹宗壽), a nephew (族子) of Cao Yanlu, fled to Guazhou (瓜州) (modern Guazhou County). In his explanation sent to the royal court of the Northern Song Dynasty after the rebellion, Cao Zongshou stated that it was because he was put in danger by Cao Yanlu. Cao Zongshou then led a rebelled army to encircle the government in Shazhou. Cao Yanlu and his brother Cao Yanrui (曹延瑞) committed suicide, and Cao Zongshou became the ruler.
After the death of Cao Zongshou in 1014, his son Cao Xianshun (曹賢順) succeeded as the ruler. Both Cao Zongshou and Cao Xianshun have sent delegations to the Northern Song Dynasty and the Liao Dynasty. The last part of history of the Guiyi Circuit was obscure. At this time, the Tanguts, who later established the Western Xia, became stronger in the surrounding region. Around 1028, the Tanguts defeated the Ganzhou Uyghurs and took Ganzhou. Around 1030, Cao Xianshun surrenderred to the Tanguts. Around 1036, the Tanguts occupied Guazhou, Shazhou, and Suzhou (肅州) (modern Jiuquan).