Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
bayhaqi:2207[Chain 1] Abū al-Ḥasan ʿAlī b. Aḥmad b. ʿAbdān > Aḥmad b. ʿUbayd al-Ṣaffār > Tamtām > ʿAffān b. Muslim > Hammām [Chain 2] ʿAlī > Aḥmad > Hishām b. ʿAlī > Ibn Rajāʾ > Hammām > Anas b. Sīrīn

[Machine] So, I saw him praying towards a donkey, and his face was turned in this direction, meaning to the left of the Qibla (the direction of prayer). So I said to him, "I saw you praying in a direction other than the Qibla." He replied, "If I hadn't seen the Messenger of Allah ﷺ doing it, I wouldn't have done it." And in a narration from 'Affan, his face was in that direction, and Humam leaned to the left of the Qibla and said at the end, "I did it, meaning the voluntary prayer."  

البيهقي:٢٢٠٧أَخْبَرَنَا أَبُو الْحَسَنِ عَلِيُّ بْنُ أَحْمَدَ بْنِ عَبْدَانَ ثنا أَحْمَدُ بْنُ عُبَيْدٍ الصَّفَّارُ ثنا تَمْتَامٌ ثنا عَفَّانُ بْنُ مُسْلِمٍ ثنا هَمَّامٌ ح وَأَخْبَرَنَا عَلِيٌّ ثنا أَحْمَدُ ثنا هِشَامُ بْنُ عَلِيٍّ ثنا ابْنُ رَجَاءٍ ثنا هَمَّامٌ عَنْ أَنَسِ بْنِ سِيرِينَ قَالَ لَقِينَا أَنَسَ بْنَ مَالِكٍ ؓ حِينَ قَدِمَ مِنَ الشَّامِ فَلَقِيتُهُ بِعَيْنِ التَّمْرِ قَالَ

فَرَأَيْتُهُ يُصَلِّي عَلَى حِمَارٍ وَوَجْهُهُ مِنْ هَذَا الْجَانِبِ يَعْنِي عَنْ يَسَارِ الْقِبْلَةِ فَقُلْتُ لَهُ رَأَيْتُكَ تُصَلِّي لِغَيْرِ الْقِبْلَةِ فَقَالَ لَوْلَا أَنِّي رَأَيْتُ رَسُولَ اللهِ ﷺ يَفْعَلُهُ مَا فَعَلْتُهُ وَفِي حَدِيثِ عَفَّانَ وَوَجْهُهُ ذَلِكَ الْجَانِبَ وَأَوْمَى هَمَّامٌ عَنْ يَسَارِ الْقِبْلَةِ وَقَالَ فِي آخِرِهِ لَمْ أَفْعَلْهُ يَعْنِي التَّطَوُّعَ  

رَوَاهُ الْبُخَارِيُّ فِي الصَّحِيحِ عَنْ أَحْمَدَ بْنِ سَعِيدٍ عَنْ حَبَّانَ عَنْ هَمَّامٍ وَرَوَاهُ مُسْلِمٌ عَنْ مُحَمَّدِ بْنِ حَاتِمٍ عَنْ عَفَّانَ

See similar narrations below:

Collected by Bukhārī
bukhari:1100Aḥmad b. Saʿīd > Ḥabbān > Hammām > Anas b. Sīrīn > Āstaqbalnā

We went to receive Anas bin Malik when he returned from Sham and met him at a place called 'Ainat- Tamr. I saw him praying riding the donkey, with his face to this direction, i.e. to the left of the Qibla. I said to him, "I have seen you offering the prayer in a direction other than that of the Qibla." He replied, "If I had not seen Messenger of Allah ﷺ doing it, I would not have done it."  

البخاري:١١٠٠حَدَّثَنَا أَحْمَدُ بْنُ سَعِيدٍ قَالَ حَدَّثَنَا حَبَّانُ قَالَ حَدَّثَنَا هَمَّامٌ قَالَ حَدَّثَنَا أَنَسُ بْنُ سِيرِينَ قَالَ

اسْتَقْبَلْنَا أَنَسًا حِينَ قَدِمَ مِنَ الشَّأْمِ فَلَقِينَاهُ بِعَيْنِ التَّمْرِ فَرَأَيْتُهُ يُصَلِّي عَلَى حِمَارٍ وَوَجْهُهُ مِنْ ذَا الْجَانِبِ يَعْنِي عَنْ يَسَارِ الْقِبْلَةِ فَقُلْتُ رَأَيْتُكَ تُصَلِّي لِغَيْرِ الْقِبْلَةِ فَقَالَ لَوْلاَ أَنِّي رَأَيْتُ رَسُولَ اللَّهِ ﷺ فَعَلَهُ لَمْ أَفْعَلْهُ رَوَاهُ ابْنُ طَهْمَانَ عَنْ حَجَّاجٍ عَنْ أَنَسِ بْنِ سِيرِينَ عَنْ أَنَسٍ ؓ عَنِ النَّبِيِّ ﷺ