Regarding istikharah prayer, it is one of the sunnah taught by the Prophet ﷺ. This is in accordance with a narration from Jabir bin Abdullah:
كَانَ رَسُولُ اللهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ يُعَلِّمُنَا الاِسْتِخَارَةَ فِي الأُمُورِ كُلِّهَا كَمَا يُعَلِّمُنَا السُّورَةَ مِنَ القُرْآنِ ، يَقُولُ: إِذَا هَمَّ أَحَدُكُمْ بِالأَمْرِ فَلْيَرْكَعْ رَكْعَتَيْنِ مِنْ غَيْرِ الفَرِيضَةِ ، ثُمَّ لِيَقُلْ : اللَّهُمَّ إِنِّي أَسْتَخِيرُكَ بِعِلْمِكَ ، وَأَسْتَقْدِرُكَ بِقُدْرَتِكَ ، وَأَسْأَلُكَ مِنْ فَضْلِكَ العَظِيمِ ، فَإِنَّكَ تَقْدِرُ وَلاَ أَقْدِرُ ، وَتَعْلَمُ وَلاَ أَعْلَمُ ، وَأَنْتَ عَلاَّمُ الغُيُوبِ ، اللَّهُمَّ إِنْ كُنْتَ تَعْلَمُ أَنَّ هَذَا الأَمْرَ خَيْرٌ لِي فِي دِينِي وَمَعِيشَتِي وَعَاقِبَةِ أَمْرِي ، أَوْ قَالَ : فِي عَاجِلِ أَمْرِي وَآجِلِهِ ، فَيَسِّرْهُ لِي ، ثُمَّ بَارِكْ لِي فِيهِ ، وَإِنْ كُنْتَ تَعْلَمُ أَنَّ هَذَا الأَمْرَ شَرٌّ لِي فِي دِينِي وَمَعِيشَتِي وَعَاقِبَةِ أَمْرِي ، أَوْ قَالَ : فِي عَاجِلِ أَمْرِي وَآجِلِهِ ، فَاصْرِفْهُ عَنِّي ، وَاصْرِفْنِي عَنْهُ ، وَاقْدُرْ لِي الخَيْرَ حَيْثُ كَانَ ، ثُمَّ أَرْضِنِي بِهِ ، قَالَ : وَيُسَمِّي حَاجَتَهُ.
“The Prophet ﷺ used to teach us the way of doing Istikharah (Istikharah means to ask Allah to guide one to the right sort of action concerning any job or a deed), in all matters as he taught us the Suras of the Qur’an. He said, “If anyone of you thinks of doing any job he should offer a two rakaat prayer other than the compulsory ones and say (after the prayer):’Allahumma inni astakhiruka bi’ilmika, Wa astaqdiruka bi-qudratika, Wa as’alaka min fadlika Al-azlm Fa-innaka taqdiru Wala aqdiru, Wa ta’lamu Wala a’lamu, Wa anta ‘allamu l-ghuyub. Allahumma, in kunta ta’lam anna hadha-lamra Khairun li fi dini wa ma’ashi wa’aqibati Amri (or ‘ajiliAmri wa’ajilihi) Faqdirhu wa yas-sirhu li thumma barik li Fihi, Wa in kunta ta’lamu anna hadha-lamra shar-run li fi dini wa ma’ashi wa’aqibati Amri (or fi’ajili Amri wa ajilihi) Fasrifhu anni was-rifni anhu. Waqdir li al-khaira haithu kana Thumma ardini bihi.'(O Allah! I ask guidance from Your knowledge, And Power from Your Might and I ask for Your great blessings. You are capable and I am not. You know and I do not and You know the unseen. O, Allah! If You know that this job is good for my religion and my subsistence and in my Hereafter (or said: If it is better for my present and later needs) Then You ordain it for me and make it easy for me to get, And then bless me in it, and if You know that this job is harmful to me In my religion and subsistence and in the Hereafter (or said: If it is worse for my present and later needs) Then keep it away from me and let me be away from it. And ordain for me whatever is good for me. And make me satisfied with it). The Prophet ﷺ added that then the person should name (mention) his need.”
Jami` at-Tirmidhi (480)