The Messenger of Allah ﷺ said, "Allah says, 'I am as My servant thinks of Me, and I am with him when he calls upon Me.'"
حدثنا أبو كريب حدثنا وكيع عن جعفر بن برقان عن يزيد بن الأصم
قال رسول الله ﷺ إن الله يقول أنا عند ظن عبدي بي وأنا معه إذا دعاني
Muslim also narrated it in the Book of Remembrance and Supplication, in the chapter on the merit of remembrance and supplication and drawing near to Allah Almighty and having good expectations of Him, hadith 2675, from Abu Kurayb through this same chain. There is also another route for it in Bukhari, hadith 7405, from Abu Hurairah through this same chain.