Leo was born in Thessaly, a cousin of the Patriarch of Constantinople, John the Grammarian. He was probably at least in part of Armenian descent. In his youth he was educated at Constantinople, but he travelled to the monasteries of Andros, where he could obtain rare manuscripts and was taught mathematics by an old monk. He originally taught privately in obscurity in Constantinople. The story goes that when one of his students was captured during the Byzantine-Arab Wars, the Caliphal-Mamun was so impressed by his knowledge of mathematics that he offered Leo great riches to come to Baghdad. Leo took the letter from the caliph to the Byzantine emperorTheophilos, who, impressed by his international repute, conferred on him a school in either the Magnaura or the church of the Forty Martyrs. In the version of the story recorded by Theophanes Continuatus, the caliph, upon receiving Leo's letter of refusal, sent a letter requesting answers to some difficult questions of geometry and astrology, which Leo obliged. Al-Mamun then offered two thousands pounds of gold and a perpetual peace to Theophilos, if only he could borrow Leo's services briefly; the request was declined. The emperor then honoured Leo by having John the Grammarian consecrate him metropolitan of Thessalonica, which post he held from the spring of 840 to 843. There is a discrepancy in this account, however, in that the caliph died in 833. It has been suggested that either the connection between the caliph's final letter and Leo's appointment as metropolitan is in error, or the caliph in question was actually al-Mutasim. This latter option squares with the account of Symeon the Logothete, who makes Leo teach at the Magnaura from late 838 to early 840 and was paid handsomely. Leo, an iconoclast sometimes accused of paganism, lost his metropolitancy with the end of the Iconoclasm in 843. Despite this, he delivered a sermon favourable of icons within months of Theophilos' death. Around 855, Leo was appointed at the head of a newly established Magnaura School by Bardas. He was renowned for his philosophical, mathematical, medical, scientific, literary, philological, astronomic, and astrological learning, and was patronised by Theoktistos and befriended by Photios I of Constantinople. Cyril was his student. Leo has been credited with a system of beacons stretching across Asia Minor from Cilicia to Constantinople, which gave advance warning of Arab raids, as well as diplomatic communication. Leo also invented several automata, such as trees with moving birds, roaring lions, and a levitating imperial throne. The throne was in operation a century later, when Liutprand of Cremona witnessed it during his visit to Constantinople.