I try to use the build in API by bitcoin client and I wonder how to get the sync status via API of a runing client.
You can do it like this:
getblockcount gives you the most recent block you have [call it n]
getblockhash n gives you the hash for that block [call it hash]
getblock hash gives you the block. You can compare the time of that block with the current time, and estimate how many blocks behind you are. It should be approximately
(now - blocktime) / 600 if the times are in seconds.