The word is of Javanese origin. Sometimes it is spelled kiai. Traditionally, students of Islam in Indonesia would study in a boarding school known as a pesantren. The leader of the school was called kyai, as a form of respect. The traditional word for a teacher in Islam is ustad, which is a Persian word. There are many ustads in Indonesia who teach the religion, but most of them do not have a boarding school.
Kiai were educated in various pesantren:
Highly motivated students went from pesantren to pesantren, studying in each the texts in which its kiai was specialised. After a few pesantrens in Banten, they would go on to pesantrens in Bogor, Cianjur, Cirebon, Central or East Java and finally, if their families could afford it, to Mecca, the most prestigious centre of Islamic learning.
A student in a pesantren is called a santri. After the founding kyai of a pesantren dies, his son or another santri may take over the supervision of the school, and would then be called kyai. It is possible for a large boarding school to have several kyai living and teaching there. However, most pesantren have a few hundred students, with only one person who is called kyai. The other teachers in the school are called ustadz. Many Indonesian Muslims consider a kyai to be higher ranked than an ustadz because a kyai runs his own boarding school and has mystical abilities.
Kiai were distinct from the pangulu, the state officials:
The pesantrens were typically (although not uniquely) located in rural districts, away from the major roads. Their geographical isolation symbolised, as it were, their ideological distance from the state. The pangulu, as a state official, and the independent teacher, the kiai, were two contrasting types, in Banten as well as elsewhere in Java."
A kyai is not a cleric in the same way as a priest in Christianity or Buddhism. There is no governing body that ordains or authorizes a kyai. Likewise, no organization can defrock a kyai or remove him from his position. The reason is that a kyai has his position and authority because people will listen to what he says.
Some Indonesians refer to a widely regarded kyai as an ulama. This word is actually the plural form of the Arabic word alim which means knowledgeable person. Through common usage in Indonesia, the word ulama grew to signify a high-level kyai, even though this is a grammatical misuse of the Arabic word.
Kyai is also a common honorific for important heirloom items in kratons in Java, like gamelan, chariot, and kris. For example, gamelan used in annual Grebeg celebration in Yogyakarta is called Kyai Sekati, itself divided into two instrumental sets: Kyai Gunturmadu and Kyai Nagawilaga. Meanwhile, Yogyakarta's royal chariot of is called Kyai Garudayaksa.
In some parts of Indonesia, famous students of the Wali Songo mystics are referred to historically as kyai or kiai or ki. One of them, Ki Ageng Gribig, is said to have returned from Mecca with a small kind of pastry which did not spoil during the long journey. To commemorate this feat, the people of Jatinom hold a festival each year, wherein thousands of these little cakes (called apem) are blessed and tossed out to participants. The main road from Klaten to Boyolali in Central Java, which passes through the town of Jatinom, is officially named after Ki Ageng Gribig, though known colloquially as Jalan Boyolali (Boyolali Road).