Liu Ruyi was the third son of Liu Bang, the founder of China's Han dynasty who became posthumously known as Emperor Gaozu ("High Ancestor"). He was the only son of the concubine Qi.
As a boy, after his uncle Liu Zhong abandoned his post during a Xiongnu invasion, Liu Ruyi was created prince or king of Dai in 200 BC.
After Zhang Ao was falsely accused of conspiring against the throne, Ruyi replaced him as prince or king of Zhao in 198 BC. The next year, he received Chen Xi as his chancellor of the realm but Chen soon launched a rebellion at Julu (within present-day Pingxiang County, Hebei); he was defeated in battle but remained at large for several years. When Liu Bang fell ill in early 195 BC, he found that Empress Lü Zhi was plotting to kill Ruyi in order to eliminate a rival claimant to the imperial throne; Liu Bang at one point had considered making Liu Ruyi crown prince, but eventually did not do so after advice from various officials, including Shusun Tong, Liu Ying's teacher. The emperor then appointed Zhou Chang as chancellor in Zhao to protect the prince from his stepmother.
The emperor died later that year, and the new emperor Liu Ying—posthumously known as the "Hui" or "Benevolent Emperor"—continued to protect his half-brother from his mother's numerous attempts on the boy's life. Lü Zhi was finally able to accomplish her task in 194 BC; she also had Consort Qi brutally tortured to death in the same year.