Xue Ji was born in 649, the same year that 's reign began. He was a great-grandson of Xue Daoheng , an important official of the Tang Dynasty's preceding Sui Dynasty, and Xue Yuanchao – a during Emperor Gaozong's reign – was a cousin to his grandfather Xue Xingcheng . Xue Xingcheng was a county magistrate, and Xue Ji's father Xue Renwei was not recorded with any official titles. However, it is known that Xue Ji's mother was a daughter of the famed chancellor Wei Zheng. Xue Ji passed the imperial examinations at one point, although the date is not known. Late in the reign of Emperor Gaozong's wife Wu Zetian, he served as an imperial attendant, along with her lovers Zhang Yizhi and Zhang Changzong and several officials with literary talents, including Ji Xu, Tian Guidao , Li Jiongxiu, and Yuan Banqian .
During Emperor Zhongzong's second reign
As of the second reign of Emperor Gaozong's and Wu Zetian's son , Xue Ji was serving as ''Zhongshu Sheren'' , a mid-level official at the legislative bureau of government . At that time, his second cousin Xue Yao was serving at the examination bureau , and both of them were known for their literary talent. Later in Emperor Zhongzong's reign, he served as ''Jianyi Daifu'' , an imperial advisor, and also served as an imperial scholar at Zhaowen Pavilion . As his grandfather Wei Zheng's household held many important literary and artistic works, he had access to many calligraphic works of Yu Shinan and Chu Suiliang, and he, following their style, was a well-known calligrapher himself. He was also an accomplished painter. At that time, Emperor Zhongzong's brother the Prince of Xiang was also a calligrapher, and he became acquainted with Xue. As part of this relationship, he married his daughter Princess Xianyuan to Xue's son Xue Boyang .
During Emperor Shang's reign and Emperor Ruizong's second reign
In 710, Emperor Zhongzong died suddenly -- a death traditional historians believed to be a poisoning carried out by his powerful wife and her daughter Li Guo'er the Princess Anle, so that Empress Wei could become "emperor" like Wu Zetian, and Li Guo'er could become crown princess. Meanwhile, Emperor Zhongzong's son by a concubine, the Prince of Wen, was named emperor , but Empress Wei retained power as empress dowager and regent. Less than a month later, Emperor Zhongzong's sister Princess Taiping and nephew the Prince of Linzi rose in rebellion and killed Empress Dowager Wei and Li Guo'er. Li Dan, himself a former emperor, was restored to the throne , displacing Emperor Shang. One of the chancellors that Emperor Ruizong commissioned was Zhong Shaojing, whose support to Li Longji was instrumental during the coup. However, Zhong was not from a prominent clan and had been a low level official previously, and this drew resentment from officials from established clans.
Xue, who had been made deputy minister of worship and had been in charge of drafting imperial edicts, along with Su Ting, suggested to Zhong that he demonstrate modesty by offering to resign -- something often done when high level officials are commissioned and mostly done ceremonially -- and when Zhong did, Xue entered the palace and persuaded Emperor Ruizong to accept the resignation. Subsequently, Xue was made ''Zhongshu Shilang'' , the deputy head of the legislative bureau, given the designation ''Canzhi Zhengshi'' , making him a chancellor ''de facto''. Soon, however, he repeatedly argued with another chancellor, Cui Riyong -- with Xue accusing Cui of flattering Wu Sansi, and Cui accusing Xue of flattering Zhang Yizhi and Zong Chuke. Emperor Ruizong, tired of their bickering, removed both of them from their chancellor posts, with Xue becoming ''Zuo Sanqi Changshi'' , a senior advisor at the examination bureau.
During Emperor Xuanzong's reign
Meanwhile, the government became divided between the parties of Princess Taiping and Li Longji, to whom Emperor Ruizong passed the throne in 712 and who took the throne as Emperor Xuanzong. After Emperor Xuanzong's enthronement, however, his struggles with Princess Taiping continued, as she continued to influence politics through Emperor Ruizong, who retained power as ''Taishang Huang'' .
By 713, it was said that Princess Taiping, Dou Huaizhen, Cen Xi, Xiao Zhizhong, Cui Shi, Xue; along with other officials Li Jin the Prince of Xinxing , Li You , Jia Yingfu , Tang Jun ; the generals Chang Yuankai , Li Ci , and Li Qin ; and the monk Huifan , were plotting to overthrow Emperor Xuanzong. It was further said that they discussed, with the lady in waiting Lady Yuan, poisoning an aphrodisiac that Emperor Xuanzong took regularly known as ''chijian'' . When this alleged plot was reported to Emperor Xuanzong by Wei Zhigu, Emperor Xuanzong – who had already received advice from Wang Ju , Zhang Shuo, and Cui Riyong to act first – did so. He convened a meeting with his brothers Li Fan the Prince of Qi, Li Ye the Prince of Xue, Guo Yuanzhen, along with a number of his associates — the general Wang Maozhong , the officials Jiang Jiao and Li Lingwen , his brother-in-law Wang Shouyi , the eunuch Gao Lishi, and the military officer Li Shoude — and decided to act first. On July 29, Emperor Xuanzong had Wang Maozhong take 300 soldiers to the imperial guard camp to behead Chang and Li Ci. Then, Jia, Li You, Xiao, and Cen were arrested and executed as well. Dou and Princess Taiping committed suicide. Emperor Ruizong yielded powers to Emperor Xuanzong and no longer actively participated in policy decisions thereafter. Xue was arrested and imprisoned at the jail of Wannian County and ordered to commit suicide. His son Xue Boyang was spared on the basis that he was the emperor's brother-in-law, but was exiled, and he committed suicide in exile.