The Kapi Agha (Turkish: Kap? a?as?, "Agha of the Gate"), formally called the Agha of the Gate of Felicity (Bâbüssaâde a?as?), was the head of the eunuch servants of the Ottoman Seraglio until the late 16th century, when this post was taken over by the Kizlar Agha. In juxtaposition with the latter office, also known as the Chief Black Eunuch as its holders were drawn from Black African slaves, the Kapi Agha is also known as the Chief White Eunuch.
As his title implies, the Kapi Agha controlled the Gate of Felicity that separated the Outer Court (Birûn, where state affairs were conducted), from the Inner Court (Enderûn) and the Sultan's private apartments in the Topkapi Palace. The Agha occupied an office to the right of the gate and had the duty of controlling entrance to the Inner Court and of transmitting the Sultan's orders to his officials, rendering him, in the words of the Ottomanist Halil ?nalc?k "the sole mediator between the Sultan and the world outside the Palace". The duties of the Kapi Agha and his white eunuchs also included running the Palace School for the pages of the palace, whose graduates then went on to become the administrative élite of the Empire. The "Mosque of the Aghas" (A?alar Camii) in the Topkapi Palace was built for use by the Kapi Agha and his eunuchs.
The office of the Kapi Agha was an influential post, the holder became a close adviser to the Sultan and could play a decisive role in the imperial succession. Holders bore the rank of vizier and came in precedence only after the Grand Vizier and the Shaykh al-Islam. In his heyday in the 15th and 16th centuries, the Kapi Agha rivalled the Grand Vizier in importance. Nevertheless, and in contrast to his analogues in other Islamic states, usually denoted by variants of the title hajib, the holders of the office never expanded their power to the extent that they could rival that of the Sultan. Unlike their counterparts, the Kapi Aghas controlled neither the administrative apparatus, which remained firmly in the hands of the Grand Vizier, nor the palace troops, which came under the command of another official, the Agha of the Janissaries, who notably also received about five times the Kapi Agha's daily salary of 100 akçes. Nevertheless, many Kapi Aghas went on to assume major provincial governorships (often distinguished by the epithet had?m, "eunuch", in their subsequent careers), and several are considered by modern historians among the greatest Ottoman statesmen of the period.
The post reached its height in the reign of Suleyman the Magnificent (1520-1566), when its holders became the stewards of the charitable foundations and endowments (vakifs) designated for the upkeep of the two holy cities (Haramayn) of Islam, Mecca and Medina, and of over seventy large mosques. During this time, the holders of the office engaged in open rivalry with the Grand Viziers for control over state affairs. Soon after, however, through the influence of the women of the Imperial Harem, the Kapi Agha was eclipsed by the Kizlar Agha, who supervised the harem. The Kizlar Agha became independent of the Kapi Agha in 1587, assumed the control of the Haramayn and quickly rose to become the senior palace official. The final blow to the authority of the office came in 1704, when its remaining powers were transferred to the Silahdar Agha. The position of the Kapi Agha survived, but thereafter was devoid of any significance.