This changes often, but taking a look at the moment:
- Login to the Google developer console: https://console.cloud.google.com/ (create an account if you do not already have a google account)
- Go to ‘library’ and search for ‘PageSpeed Insights API’
- Click ‘Enable’ on the pagespeed insights API. (this will say ‘Manage’ if you’ve already previously enabled it)
- Go to your ‘APIs & Services’ Credentials page. I got there by clicking the hamburger menu in the top left of the page. (screeshot: https://cloudup.com/cZlAvVGtMiD)
- Click the ‘Create Credentials’ button from the top of the page, and select ‘API key’
- An API Key should pop up right away. I recommend you do testing with this API key before putting in place any restrictions, as I’ve found the restrictions are often incompatible with the Pagespeed Insights API
I hope this helps.