Skip to content

Creating a PageSpeed API key

An API key is a long code from Google that lets Permo request PageSpeed Insights tests for your pages. It’s free, and it belongs to your own Google account. Without a key, Permo measures your server and sends nothing to Google; with a key, every check also runs PageSpeed Insights for mobile and desktop.

Creating one takes a few minutes and a Google account.

Google offers PageSpeed Insights to anyone, and recommends a key for regular, automated tests (source below). Permo runs its tests on a schedule, so it uses one. Because the key is yours, the tests count against your own free allowance at Google, and you can see or stop them at any time in your Google account.

  1. Open Google’s guide Get Started with the PageSpeed Insights API and select Get a Key. Google asks you to sign in and to choose or create a project; any name works.

    You can also create the key in the Google Cloud Console, under APIs & Services → Credentials → Create credentials → API key. In that case, also open APIs & Services → Library, search for PageSpeed Insights API and select Enable.

  2. Copy the key. It’s a long string of letters, digits, dashes and underscores.

A restriction makes sure the key can only be used for what it’s meant for. In the Google Cloud Console, open APIs & Services → Credentials and select your key.

  • API restrictions: choose Restrict key and select only the PageSpeed Insights API. Then the key is of no use for anything else, even if someone copies it.
  • Application restrictions: leave this at None. This is the setting that most often goes wrong. A restriction to websites only allows requests from a visitor’s browser, but Permo sends its requests from your server, so Google rejects all of them. A restriction to IP addresses works only if it includes your server’s address, and that address can change when your hosting provider moves your site.

Save the changes. Google notes that they can take a few minutes to apply.

  1. In WordPress, open Performance Monitor → Settings, tab General.
  2. Paste the key into the card PageSpeed Insights API key and select Save key.
  3. Permo tests the key with Google. If it works, you see The key works. Permo is measuring your homepage now. The results appear on the PageSpeed screen once Google has tested the page on a phone and a desktop computer.

After saving, the card only shows the last characters of the key (Saved, ends in …). Permo never sends the key back to your browser. Test key checks it again, Change replaces it, and Delete removes it: PageSpeed tests stop, and Permo keeps measuring your server.

The guide in that card has the same steps; the info button next to the title opens it.

Each check sends one request per page and device. With ten pages and a daily check, that’s about 20 requests a day, plus one for each manual check and each key test. Google shows your limit and your usage in the Google Cloud Console, on the Quotas page of the PageSpeed Insights API.

For each test, Permo sends the address of the page, the device (mobile or desktop), the requested categories, your site’s language and the key, which travels in a request header and not in the address. Google then loads that page like any visitor would. A key test sends only the key, without a page address.

Permo shows Google’s answer as a sentence on the settings page. The most common ones:

Message What it means
The key is restricted to websites, so Google rejects requests from your server. Remove the website restriction. Set Application restrictions to None (see above).
The key only allows IP addresses that do not include this server. Add your server’s address to the IP list, or set Application restrictions to None.
Google rejects the key because of an application restriction. Another kind of application restriction blocks the request. Set it to None.
The key may not use the PageSpeed Insights API. Add the API under API restrictions. The API restriction leaves out PageSpeed Insights. Select it under API restrictions.
The PageSpeed Insights API is not enabled in the key’s Google Cloud project. Enable it under APIs & Services → Library in the project the key belongs to.
Google does not accept this API key. Check it in the Google Cloud Console or create a new one. The key was mistyped, deleted, or belongs to a project that no longer exists.
The key has used up its quota at Google. Permo tries again at the next check. Google’s limit is reached for now. Nothing to fix; the next check runs normally.
The API key was not saved: it contains characters that a Google API key does not have. Usually a space or line break was copied along. Paste the key again.

Sources