Hi @Padathuvali Joseph ,
We get this query quite a lot here on community.
There is no API to get the VM uptime/running hours directly. However, you can formulate your own Log Analytics Query to query the heartbeat of the VM through Azure Log Analytics Workspace using Azure Monitor, but it might not always be accurate because if in any case the VM agent goes down, then the heartbeat of the VM will not be reported back to the Azure Platform.
There is an already thread existing on community. You can refer to that below.
#906519
Do let me know if this helps. If it doesn't help, please reach back so that I can look into this further :)
Thanks.