The Messenger of Allah ﷺ said to him, "Keep the marriage proposal private, then perform ablution and do it well, and pray whatever Allah has decreed for you. Then praise your Lord and glorify Him, and say, 'O Allah, You have power and I have none, You know and I do not, You are the Knower of all unseen things. If You see that so-and-so,' naming her by name, 'is good for me in my religion, my worldly life, and my hereafter, then decree her for me. But if another is better for me than her in my religion, my worldly life, and my hereafter, then decree that one for me,'" or he said, "ordain her for me."
حدثنا حسن حدثنا ابن لهيعة حدثنا الوليد بن أبي الوليد عن أيوب بن خالد بن أبي أيوب الأنصاري حدثه عن أبيه
أن رسول الله ﷺ قال له اكتم الخطبة ثم توضأ فأحسن وضوءك وصل ما كتب الله لك ثم احمد ربك ومجده ثم قل اللهم إنك تقدر ولا أقدر وتعلم ولا أعلم أنت علام الغيوب فإن رأيت لي في فلانة تسميها باسمها خيرا في ديني ودنياي وآخرتي وإن كان غيرها خيرا لي منها في ديني ودنياي وآخرتي فاقض لي بها أو قال فاقدرها لي
Its chain of transmission is hasan. Hakim graded the hadith sahih (1/314), and said, "The sunnah of the prayer of istikhara is rare, transmitted solely by the people of Egypt," and Dhahabi agreed with him. The hadith is also found in Tabarani's Al-Kabir (4/133, no. 3901), Ibn Hibban (177, no. 685), and Bayhaqi (7/147).