He appears in the early 9th century as a follower of the rebel governor Rafi ibn al-Layth, but quickly abandoned him along with most of the people of Fergana and Tashkent when Caliph Harun al-Rashid himself campaigned to Khurasan in 808.
[1][2]'Ujayf probably belonged to the same social group as the other eastern Iranian generals who were later employed by al-Mu'tasim in his "Turkish" guard, and who were minor princes or drawn from the landed gentry (dihqans).
[1] Ujayf maintained his position under Mu'tasim, Ma'mun's half-brother and successor, campaigning against the Zutt in southern Iraq in 834, and leading a number of expeditions against the Byzantines in Asia Minor.
[1] Ujayf was one of the military leaders to receive cantonments for themselves and their troops at Mu'tasim's new capital at Samarra,[5] and he was granted the revenue from the market of the town of Ishtikhan (near Samarkand) as a reward.
Ujayf was probably a leading member of a powerful group within the Abbasid military establishment that already back in 833 had opposed Mu'tasim's accession, and had favoured his nephew, Ma'mun's son al-Abbas.