There are some post about using PageSpeed API using different languages:
And the official Google APIs Client Libraries.
Also take into account that Google imposes a quota limit on PageSpeed Insights API usage.
It would be useful to share in which programming language you are writing your code if you are not throttling the API’s quota.