---
title: "Get a PageSpeed Insights API Key"
description: "Step-by-step guide to getting a free PageSpeed Insights API key from Google Cloud Console. Setup takes 2 minutes."
canonical_url: "https://unlighthouse.dev/learn-lighthouse/pagespeed-insights-api/get-api-key"
last_updated: "2025-01-18"
---

> Index of every page on this site: [llms.txt](https://unlighthouse.dev/llms.txt)

Free API key setup in 2 minutes. No billing required for the free tier.

## Steps

### 1. Open Google Cloud Console

Go to [console.cloud.google.com](https://console.cloud.google.com)

Sign in with any Google account. You don't need a paid Google Cloud account - the PSI API has a free tier.

### 2. Create or Select a Project

Click the project dropdown at the top of the page:

- **New users:** Click "New Project", give it a name like "PSI Testing", and create
- **Existing users:** Select an existing project or create a new one

### 3. Enable the PageSpeed Insights API

1. Go to **APIs & Services** → **Library** (or search "API Library" in the top search bar)
2. Search for **"PageSpeed Insights API"**
3. Click on it and press **Enable**

The API is now active for your project.

### 4. Create Credentials

1. Go to **APIs & Services** → **Credentials**
2. Click **Create Credentials** → **API Key**
3. Copy the key that appears

Your key is ready to use immediately.

## Secure Your Key

API keys can be stolen and abused. For example, [exposed API keys can lead to significant unauthorized charges](https://cloud.google.com/docs/authentication/api-keys#securing_an_api_key) if attackers use them to call other billable GCP APIs. Always add restrictions.

### For Server-Side Use

Restrict by IP address:

1. Click on your API key in the Credentials list
2. Under **Application restrictions**, select **IP addresses**
3. Add your server's IP address(es)
4. Save

**Note:** IP restrictions [don't work with serverless platforms](https://vercel.com/kb/guide/can-i-get-a-fixed-ip-address) (Vercel, Cloudflare Workers, AWS Lambda) since they use dynamic IPs. Use HTTP referrer restrictions or a server-side proxy instead.

### For Client-Side Use

Restrict by HTTP referrer:

1. Click on your API key in the Credentials list
2. Under **Application restrictions**, select **HTTP referrers**
3. Add your domain: `yourdomain.com/*`
4. Save

### API Restrictions (Critical)

**Always** limit the key to only the PSI API - this prevents the billing nightmare above:

1. Under **API restrictions**, select **Restrict key**
2. Choose **PageSpeed Insights API** from the dropdown
3. Save

## Test Your Key

Verify it works with a curl request:

```bash
curl "https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=https://example.com&key=YOUR_API_KEY"
```

A successful response returns JSON with Lighthouse data. An invalid key returns:

```json
{
  "error": {
    "code": 400,
    "message": "API key not valid. Please pass a valid API key."
  }
}
```

## Quotas

| Limit                             | Value  |
| --------------------------------- | ------ |
| Requests per day                  | 25,000 |
| Requests per minute               | ~240   |
| Requests per 100 seconds per user | 60     |

Monitor usage at **APIs & Services** → **PageSpeed Insights API** → **Quotas**.

The daily limit resets at midnight Pacific Time. Official Google Cloud quotas specify a default of 25,000 queries per day and 400 queries per 100 seconds (approx. 4 queries per second). Monitor and manage your limits in the [Google Cloud Console](https://console.cloud.google.com/apis/api/pagespeedonline.googleapis.com/quotas). Your actual limits may vary based on project history and usage.

**Set up quota alerts:** Go to **IAM & Admin** → **Quotas & System Limits** → find PageSpeed Insights API → **Create usage alert** at 50%, 80%, and 95% thresholds.

**For higher limits:** Create multiple GCP projects (each gets its own 25k/day quota) or request a quota increase in the Quotas section. Google is reportedly reasonable about increases for legitimate use cases.

## Next Steps

- [Node.js integration](https://unlighthouse.dev/learn-lighthouse/pagespeed-insights-api/node-example)
- [Python integration](https://unlighthouse.dev/learn-lighthouse/pagespeed-insights-api/python-example)
- [Handle rate limits](https://unlighthouse.dev/learn-lighthouse/pagespeed-insights-api/rate-limits)

## Skip the API Key Dance

Unlighthouse runs Lighthouse locally - no API keys, no quotas, no Google Cloud Console.

```bash
npx unlighthouse --site https://your-site.com
```

::u-button
```yaml [props]
to: /
size: lg
label: Try Unlighthouse
icon: i-heroicons-rocket-launch
```
::

## Sitemap

See the full [sitemap](https://unlighthouse.dev/sitemap.md) for all pages.
