Cao Ni (died 323) was a Chinese military general of Han Zhao and warlord during the Jin dynasty (266–420) and Sixteen Kingdoms period. He was one of the followers of the bandit Wang Mi and followed him into service with Liu Yuan's state of Han. Wang Mi entrusted him to secure his family in Qingzhou, but after Wang Mi was killed by Shi Le in 311, Cao Ni gradually became an independent warlord, causing much concern in the Han Zhao court. He was finally killed in 323 when Shi Le sent his nephew Shi Hu to subdue him once and for all. His name can be rendered as Cao Yi. 

Cao Ni left an important mark in 4th century China with the formation of Guanggu City (廣固, in modern Qingzhou, Shandong). The city became his capital after he took over the region and would continue to serve as such to the states after his death, Duan Qi and Southern Yan.

As a follower of Wang Mi 
Cao Ni was from Donglai Commandery, the same commandery where his master, Wang Mi, was from. He appeared to have joined Wang Mi some time in 306, during which Wang Mi joined the failed rebellion of Liu Bogen (劉柏根) in Donglai. Wang was defeated, became a bandit and terrorized northern China before formally joining Liu Yuan's state, Han Zhao in 308. At that time, Cao Ni was serving as Wang's Chief Clerk of the Left. In 309, Wang Mi convinced Liu Yuan to make Cao Ni the acting General Who Maintains The East. Wang Mi also asked Liu Yuan to position Cao Ni in Qingzhou, where he would help Wang protect secure his family. In Qingzhou, as per Wang Mi's advice, he recruited the local fugitives in Donglai in order to strengthen his numbers.

Service under Han Zhao 
At the time of Cao Ni's entry into the state, Han Zhao was in the midst of warring with Jin in the north. Cao Ni first contributed to the state by taking Dongping County in 310. He then proceeded to capture Langya Commandery, forcing the regional commander, Gou Chun (苟纯) to hole himself up in his city. Cao Ni's capture of Langye placed him in control of most of the ancient Qi region, which caught the Jin court's attention. Jin's head commander in the north, Gou Xi, was sent to save Qingzhou, where he continuously routed Cao Ni. However, the tides changed the following year in 311 as Cao Ni dealt him a decisive defeat, causing Gou Xi to abandon his campaign and flee to Gaoping.

After securing the region, Cao Ni built a new city for Qingzhou known as Guanggu City. Guanggu possessed a terrestrial advantage over invaders as it was surrounded by ravines on all sides, serving as natural moats. Cao Ni initially based himself in Linzi, which was the traditional provincial capital at the time, but later in his years as Qingzhou's warlord, he shifted his base to Guanggu due to its impregnable defences. The city of Guanggu played an important role during the Sixteen Kingdoms period. In 350, it was the capital of the state of Duan Qi and in 399 it became the capital of Southern Yan. The city went into obscurity after the Jin general Liu Yu captured it and ended Southern Yan in 410.

The Jin capital of Luoyang fell to Liu Yao, Huyan Yan, and Wang Mi that year while Gou Xi was captured by Shi Le. However, cracks were beginning to appear between Wang Mi and his peers Liu Yao and Shi Le. Shi Le in particular made him suspicious, so Wang Mi sent his official Liu Tun (劉暾) to Qingzhou to order Cao Ni to prepare his troops against Shi Le. However, Cao Ni never knew of the plan as Shi Le's scouts captured Liu Tun. Furthermore, Wang's subordinates, Xu Miao (徐邈) and Gao Liang (高梁) left Wang Mi and took their armies over to Cao Ni. Wang Mi's suspicion over Shi Le costed him by the end of 311 after Shi Le lured him to a banquet and assassinated him. After Wang's death, Cao Ni remained in Qingzhou.

As an independent warlord 
With Wang Mi dead, Cao Ni was left to his own devices. For the next few years, Cao Ni led a conquest of the Qi and Lu region. He first took Wenyang Pass (汶陽關) and Gongqiu (公丘, in present-day northern Anhui and northwestern Jiangsu) after defeating and killing the Jin Administrator of Qi, Xu Fu (徐浮). This victory caused forty fortified cities within Qi and Lu to surrender to him. He then pressed on into Zhu'e and Pingyin, also annexing the areas. By 315, Cao Ni had conquered all of Qi and Lu and positioned his troops along the Yellow River, creating concerns for his rival warlord Shi Le. Shi Le asked Liu Cong for permission to subdue Cao Ni but Liu Cong, fearing that Shi Le will control Qingzhou after defeating Cao Ni, refused to allow him.

Between 312 and 315, it is said that Cao Ni uncovered the tombs of two Spring and Autumn period figures: the philosopher Guan Zhong and Duke Jing of Qi. Both tombs were plundered by Cao Ni and his men, who amassed a huge fortune from their doings. 

Cao Ni's position unsettled a few of Liu Cong's advisors. In 313, during his opposition towards Liu Cong's building projects, Chen Yuanda cited Cao Ni as a major concern along with Shi Le as the two men were sending tribute and reports less and less. Much later in 317, Cao Ni was once again mentioned as a threat to Han Zhao by another of Liu Cong's advisors, Kang Xiang (康相). 

Despite worries about Cao Ni's strength, he maintained a rather passive stance throughout his rule over Qingzhou. He was constantly changing allegiance between his stronger neighbours. In 316, he agreed to a secret alliance with Shi Le without Liu Cong's knowledge. In 317, Cao Ni was one of the many warlords to offer his allegiance to Jin and urge Sima Rui to take the throne. He was accepted as a vassal, but his request for Rui to declare himself emperor was met with rejection that year. However, Cao Ni soon realized that Jiankang was too far away from his base to protect him, so he dropped his loyalty to Jin and offered his vassalage to Shi Le instead in 318. Shi Le agreed and made him Grand General of the Eastern Provinces, Governor of Qingzhou, and Duke of Langye. 

During his short time as a Jin vassal, Cao Ni had taken notice of a certain Su Jun, a refugee leader living within Cao Ni's territory. Cao Ni wanted to make him Prefect of Ye County, but Su Jun pretended to be ill in order to avoid him. As time passed by, Cao Ni grew worried about Su Jun, who was gathering a sizeable group of refugees under his wing. Cao Ni planned to get rid of him in 319, but Su Jun learned about this and fled through the sea with his followers to Eastern Jin, where he became a prominent general but later a dangerous rebel. That same year, Cao Ni sent funds to Shi Le, asking him to make the Yellow River a border between the two, to which he agreed. 

Ever since Cao Ni had taken over Qingzhou, he could not secure Donglai commandery, which was controlled by the Jin administrator, Ju Peng (鞠彭). Although Cao Ni had the upper hand in terms of strength, the people of Donglai were zealous in resisting him under Ju Peng. The two constantly fought with each other but after many years, Ju Peng began to express regret over his war as he realized the toll it took on the people of Donglai. In order to prevent further bloodshed, Ju Peng decided to flee to Liaodong in 319, leaving the people of Donglai under Cao Ni's administration and thus ending the conflict.

Cao Ni's life came to an end in 323. He once again switched his allegiance to Jin and became their General Who Maintains the East that year. In response, Shi Le's nephew Shi Hu attacked him. Many of Qingzhou's counties and commanderies quickly surrendered to him, leaving Cao Ni with only Guanggu to defend. Shi Hu placed the city under siege but not long after, Cao Ni came out and surrendered. Cao Ni was sent to Shi Le's capital in Xiangguo (襄國, in modern Xingtai, Hebei), where he was executed while his forces were decimated by Shi Hu through burying alive.

Descendant 
Although Cao Ni died through capital punishment, at least a child or a grandchild of his managed to survive the aftermath of Shi Hu's attack. In 356, Ju Peng's son, Ju Yin (鞠殷) was appointed by the Former Yan general Murong Ke to govern Donglai. Ju Peng was still alive that year and was also serving Yan as Manager of the Empress's Staff. Ju Peng believed that Wang Mi and Cao Ni had descendants living in Donglai, so he wrote to his son urging him to end their family feud. Ju Yin discovered that Cao Yi's grandson Cao Yan (曹巖) and Wang Mi's nephew Wang Li (王立) were living among the hills. The three men befriended one another while Ju Peng gifted them with carts, horses, and clothing.

References 

 Fang, Xuanling (ed.) (648). Book of Jin (Jin Shu)
 Sima, Guang (1084). Zizhi Tongjian
 Li, Fang (983). Taiping Yulan

323 deaths
Former Zhao generals
Jin dynasty (266–420) generals
Chinese warlords
4th-century executions
Executed Sixteen Kingdoms people