# PageSpeed Audit (`pontio/pagespeed-audit`) Actor

Batch Google PageSpeed Insights audits for supplied URLs, using your own free Google API key. Lighthouse scores and metrics; failed checks are uncharged.

- **URL**: https://apify.com/pontio/pagespeed-audit.md
- **Developed by:** [Gabor Molnar](https://apify.com/pontio) (community)
- **Categories:** Developer tools, SEO tools, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.40 / 1,000 pagespeed audit checkeds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## PageSpeed Audit

Run Google's PageSpeed Insights / Lighthouse performance audit for a batch of supplied URLs.

This Actor is intentionally narrow: it calls the official PageSpeed Insights API for the URL and strategy you provide, returns the performance score, core timing metrics and the top savings opportunities. It does not crawl a site, run a browser itself, or guarantee Google can fetch every page.

### Input

```json
{
  "urls": ["https://example.com"],
  "strategies": ["mobile"],
  "apiKey": "your Google PSI API key"
}
```

- `urls`: 1–50 HTTP(S) URLs. Credentials, localhost and non-80/443 ports are refused.
- `strategies`: `mobile`, `desktop`, or both. Each URL/strategy pair is one row.
- `apiKey`: your own Google PageSpeed Insights API key. Google gives one free: see [Get Started with the PageSpeed Insights API](https://developers.google.com/speed/docs/insights/v5/get-started). Apify stores it encrypted and it never appears in a result row. In practice you need one: without it the run uses Google's shared keyless quota, which is often exhausted, and rows come back `rate_limited`. Those rows are free. A key that Google rejects normally gives `upstream_error` with `httpStatus` 400. Google has also answered a rejected key with 429, which shows as `rate_limited`. Both are free.
- Canonical repeats are audited once per strategy.

### Output

Each row includes:

- `url`, `strategy`, `finalUrl`
- `performanceScore` from Lighthouse, 0–100
- metrics: first contentful paint, largest contentful paint, total blocking time, cumulative layout shift and speed index
- up to 10 Lighthouse opportunities with estimated savings
- `reasonCode`

### Billing

One charge per completed audit. Everything else is free.

| reasonCode | Meaning | Charged? |
| --- | --- | --- |
| `audited` | Google PSI returned a valid Lighthouse performance result. | yes |
| `invalid_url` | The submitted URL is malformed or outside this Actor's URL limits. | no |
| `rate_limited` | PageSpeed Insights returned HTTP 429. Respect `retryAfter`. | no |
| `upstream_error` | PageSpeed Insights or the network failed. | no |
| `invalid_response` | PageSpeed Insights returned JSON this Actor could not validate. | no |

No start fee. Failed audits are free. Processing stops at the run's charge limit; URLs not reached get no row.

### Limits

- Uses Google's PageSpeed Insights API; Google may throttle, reject or fail pages independently of this Actor.
- One PSI API request per URL/strategy pair, processed sequentially.
- Performance data is a point-in-time Lighthouse result, not a monitoring history.

# Changelog

This Actor's version history is a separate document: https://apify.com/pontio/pagespeed-audit/changelog.md

# Actor input Schema

## `urls` (type: `array`):

Up to 50 HTTP(S) URLs. Canonical repeats are audited once per strategy. Google PageSpeed Insights fetches the page; failures are uncharged.

## `strategies` (type: `array`):

Run mobile, desktop, or both. Each URL/strategy pair is one audit row.

## `apiKey` (type: `string`):

Your own Google PageSpeed Insights API key, free from Google. Without it the run uses Google's shared keyless quota, which is often exhausted and then returns free rate_limited rows.

## Actor input object example

```json
{
  "urls": [
    "https://example.com"
  ],
  "strategies": [
    "mobile"
  ]
}
```

# Actor output Schema

## `results` (type: `string`):

Results produced by this run, in its default dataset.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "urls": [
        "https://example.com"
    ],
    "strategies": [
        "mobile"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("pontio/pagespeed-audit").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "urls": ["https://example.com"],
    "strategies": ["mobile"],
}

# Run the Actor and wait for it to finish
run = client.actor("pontio/pagespeed-audit").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "urls": [
    "https://example.com"
  ],
  "strategies": [
    "mobile"
  ]
}' |
apify call pontio/pagespeed-audit --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,pontio/pagespeed-audit"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/dt7874B1E9BPuKmiL/builds/lkCzFKgdAKJK9iIkq/openapi.json
