---
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"
---

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

<table>
<thead>
  <tr>
    <th>
      Limit
    </th>
    
    <th>
      Value
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      Requests per day
    </td>
    
    <td>
      25,000
    </td>
  </tr>
  
  <tr>
    <td>
      Requests per minute
    </td>
    
    <td>
      ~240
    </td>
  </tr>
  
  <tr>
    <td>
      Requests per 100 seconds per user
    </td>
    
    <td>
      60
    </td>
  </tr>
</tbody>
</table>

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](/learn-lighthouse/pagespeed-insights-api/node-example)
- [Python integration](/learn-lighthouse/pagespeed-insights-api/python-example)
- [Handle rate limits](/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 icon="i-heroicons-rocket-launch" label="Try Unlighthouse" size="lg" to="/">



</u-button>
