If you had installed Keynote on macOS since Oct 2013, then you can get Keynote for Sonoma. If Keynote was pre-installed by Apple, a third-party reseller, or a previous owner of this Mac, then you will be relegated to using Keynote in iCloud only. Or another tool like LibreOffice Impress, or Microsoft Powerpoint.
Only if you personally installed Keynote v5 or later in the past, launch the Mac App Store and sign-in with the same Apple ID you used to previously install Keynote. Press cmd+0 (zero) to open the App Store Purchases page. If you see Keynote there, click the blue outline download icon. You may see one or more dialogs. Do not click Cancel on them, and the last dialog should ask you if you want to install the last compatible version of Keynote for Sonoma. You know what to do.