Sahih al-Bukhari, Book 97, Hadith 178 (In-Book) ⓘ
Narrated Abu Huraira: I heard Allah's Messenger saying, "Before Allah created the creations, He wrote a Book (wherein He has written): My Mercy has preceded my Anger." and that (Book) is written with Him over the Throne."
وَقَالَ لِي خَلِيفَةُ بْنُ خَيَّاطٍ حَدَّثَنَا مُعْتَمِرٌ، سَمِعْتُ أَبِي، عَنْ قَتَادَةَ، عَنْ أَبِي رَافِعٍ، عَنْ أَبِي هُرَيْرَةَ، عَنِ النَّبِيِّ صلى الله عليه وسلم قَالَ " لَمَّا قَضَى اللَّهُ الْخَلْقَ كَتَبَ كِتَابًا عِنْدَهُ غَلَبَتْ ـ أَوْ قَالَ سَبَقَتْ ـ رَحْمَتِي غَضَبِي. فَهْوَ عِنْدَهُ فَوْقَ الْعَرْشِ " .
also referenced under: Hadith 7553 (DarusSalam) & Volume 9, Book 93, Hadith 643 (USC-MSA)