Check the connector pins on the Surface itself for dust, debris, or bent/dirty contacts. A soft brush or gently blowing compressed air on them often fixes this.
Try a full shutdown and restart — hold the power button for a few seconds to force it, then power back on with the keyboard attached.
Reseat the keyboard a few times — sometimes the magnetic connection isn't fully seated even though it looks attached.
Check Device Manager for any "Surface Type Cover" entry with a warning icon — if so, try uninstalling and letting Windows reinstall the driver.
Update firmware via Windows Update or the Surface app if you can get any input method working.
If none of that resolves it, it's likely a hardware issue with the connector pins inside the Surface itself.
Troubleshoot Surface Pro Keyboard or Type Cover
If the device was registered, go to account.microsoft.com/devices and it'll list the serial number for devices tied to your account.
Settings → System → About. This shows the serial number in on-screen text.
power off, then power on while holding Volume Up, or press Power + Volume Up when the device is off, to enter Surface UEFI. The serial is usually listed there too.