The idea of a waking prayer is first referred to in the Talmud (Ber. 60b; J. Ber. 80:4), but this form arises out of 16th century mysticism:
מוֹדֶה אֲנִי לְפָנֶיךָ מֶלֶךְ חַי וְקַיָּם, שֶׁהֶחֱזַרְתָּ בִּי נִשְׁמָתִי בְּחֶמְלָה. רַבָּה אֱמוּנָתֶךָ.
I give thanks to You, living and eternal King,
for You have mercifully restored my soul within me;
great is Your faith.
The phrase, "Great is Your faith" is biblical, an abridged version of "...they are new every morning, great is Your faith" (Lam.3:22-23), but what really drives this prayer is the lurianic interpretation of the verse as referring to the soul's night time journey out of the body into the higher realms (the Seven Heavens of early Jewish cosmology; the Sefirot of Medieval mysticism) that also inspires the prayers Elohai Neshamah and Oden LaEl. Luria and those who follow him, notably Nachman of Bratzlav (Likkutei Moharan B 84), are struck by the literal meaning, which suggests that it is God who has faith. What does God have faith in? That human souls (the "they" in the Lamentations verse) will continue to grow and evolve towards higher levels over the course of its time inhabiting a body. The soul, they argue, departs the body each night and goes to the divine realm called "Faith," where it undergoes renewal, readied for the trials it will face and growth it will (hopefully) undertake during the waking hours in the Asiyah, the World of Action.
So important is it to recite this prayer immediately upon returning to consciousness that it is composed without the inclusion of any divine names, so that the person does not have to wash or make other spiritual preparations before reciting it.