As I understand it, OP was hoping there was a way to get the No of keys as a direct/immediate answer, that his system could make use of. REgarding this, I think my answer above is correct.
There IS a general SYSEX command that will request the device ID, and this will usually get an answer back, but the information provided would not immed help OP, as there would be a Mfg code, and a device code, and the codes are numbers. Sema's system linked above has created a list of devices (with names) and the numbers returned by the device ID request, so that there can be a look-up to translate the code obtained to a more useful designation that might be in the box or the keyboard body, i.e. GRX-88. Such a look-up will always be problematic, not every older device will be on it, and newer devices will need adding pretty much all the time.
I have a fairly old Casio keyboard which is midi capable and quite useful, however if has ZERO SysEx capability so you will get no reply from any Device ID enquiry! No doubt there are many other similar keyboards?
Geoff