At the time that the general An Lushan rebelled at Fanyang (范陽, in modern Beijing) in 755 and soon established a new state of Yan, An Baoyu was defending Nanyang (南陽).
Emperor Suzong granted him the imperial surname of Li, and also permitted him to change his designated home to Chang'an—considered a substantial honor at the time.
[2] Li Baoyu was also made the military governor (jiedushi) of Chenzheng Circuit (陳鄭, headquartered in modern Zhengzhou, Henan).
In 761, however, when the eunuch official Yu Chao'en pressured Li Guangbi into trying to recapture Luoyang – which ended in spectacular failure—Li Baoyu was also forced to abandon Heyang and flee, apparently to Ze Prefecture (澤州, in modern Jincheng, Shanxi), for in 762, that was the location that Shi Siming's son and successor Shi Chaoyi put Li Baoyu under siege, which was lifted when the major general Guo Ziyi sent the Dingguo Army (定國軍) to aid him, allowing Li Baoyu to turn the tables on the Yan forces and defeat them.
He also wanted to create Li Baoyu the Prince of Wuwei, but Li Baoyu earnestly declined the princely title; instead, Emperor Daizong created him the Duke of Liang and gave him the honorific title of Sikong (司空)—one of the Three Excellencies.
Later in 762, Li Baoyu participated in the joint Tang and Huige campaign to recapture Luoyang, and after Luoyang fell and Shi Chaoyi fled, a number of Yan generals submitted to Tang—but then were permitted to remain at their posts by the major Tang general Pugu Huai'en.
Li Baoyu and another Tang general, Xin Yunjing (辛雲京), thus suspected Pugu of planning to rebel and warned Emperor Daizong of such.
(Pugu was in fact fearful that the imperial government would no longer consider him important and therefore planned an alliance with these former Yan generals, and did eventually rebel in 763.
In 764, Emperor Daizong gave Li Baoyu the additional responsibility of being the military governor of Fengxiang Circuit (鳳翔, headquartered in modern Baoji, Shaanxi) and put him in charge of the operations against the bandits.
In 770, as part of Emperor Daizong's plot with the chancellor Yuan Zai to kill Yu Chao'en, who had by then become overbearingly powerful, Yuan's ally Huangfu Wen (皇甫溫) was moved from Shan Circuit (headquartered in modern Sanmenxia) to Fengxiang, while Li Baoyu was moved from Fengxiang to Shannan West Circuit (山南西道, headquartered in modern Xi'an, Shaanxi, to the southwest of Chang'an).