Li Gao
It is not known when Li Wei was born. He was from the Guzang Branch of the Li clan of Longxi, which, like Tang Dynasty's imperial clan, claimed ancestry from Li Gao, the founder of the Sixteen Kingdoms period state Western Liang — with the Tang imperial clan descended from Li Gao's second son Li Xin (Western Liang's second duke) and Li Wei's ancestors descended from Li Gao's eighth son Li Fan () and Li Fan's son, the prominent Northern Wei general Li Bao (). Subsequent male-line ancestors of Li Wei's served as officials of Northern Wei, Sui Dynasty, and Tang. Li Wei's grandfather Li Shanggong () served as the director of the archival bureau (秘書監, "Mishu Jian"), while his father Li Jingsu () served on the staff of a Crown Prince.