> ## Documentation Index
> Fetch the complete documentation index at: https://docs.corsair.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# GTmetrix plugin

> GTmetrix page speed testing: start Lighthouse or metrics-only tests from 20+ locations and browsers, read reports (grade, Core Web Vitals, timings, page size), download screenshots, HAR files, videos and PDFs, and manage pages, monitoring, alert conditions and page tags (34 operations).

Use **GTmetrix** through Corsair: one client, typed API calls, local DB sync.

Get a key at [https://gtmetrix.com/dashboard/account](https://gtmetrix.com/dashboard/account) (API Usage > Generate
API Key). The key is the HTTP Basic username; the password is empty.

* **Credits**: tests spend API credits. A Lighthouse report costs 1, a
  legacy PageSpeed/YSlow report 0.7, both 1.1 and a metrics-only report
  (`report: "none"`) 0.6; video adds 0.9 and longer retention up to 1.8.
  `reports.retest` and `pages.retest` cost the same as `tests.start`, and
  `reports.resource` with `report.pdf` costs 0.2 (0.3 full). A free Basic
  account gets a few one-off credits; `status.get` shows the balance.
* **Running a test**: `tests.start` answers at once with a queued test.
  Poll `tests.get` every few seconds; when the test is done GTmetrix
  redirects to the report and `tests.get` returns the report itself
  (`data.type` is `report`).
* **Files**: `reports.resource` returns the file as `text` (JSON, HAR) or
  `contentBase64` (images, video, PDF, tar). The documented
  `resource-summary` is served as `resource-summary.json`; both names work.
  `analysis-options` includes the cookies and HTTP auth the test used.
* **Lists** take `page`, `pageSize` (up to 500), `sort` (`-created`) and
  `filter` (`{ "state": "completed" }`, `{ "created:gt": 1764600000 }`).
  Each answer carries `next_page`, null on the last page.
* **Risk levels**: reads are `read`; starting tests, retests, monitoring,
  alert conditions and tag changes are `write`; deleting reports, pages,
  tags and alert conditions is `destructive`.
* `status.get` drops `data.id`, which GTmetrix fills with the API key.
  With a database, tests, reports, pages and tags are kept in their own
  tables; report files never are.

**What you get:**

* 34 typed API operations
* 4 synced entities (`pages`, `reports`, `tags`, `tests`) for fast `.search()` / `.list()`

## Setup

**1. Install**

```bash npm theme={null}
npm install corsair @corsair-dev/gtmetrix better-sqlite3
npm install --save-dev @types/better-sqlite3
```

```bash yarn theme={null}
yarn add corsair @corsair-dev/gtmetrix better-sqlite3
yarn add --dev @types/better-sqlite3
```

```bash pnpm theme={null}
pnpm install corsair @corsair-dev/gtmetrix better-sqlite3
pnpm install --save-dev @types/better-sqlite3
```

```bash bun theme={null}
bun add corsair @corsair-dev/gtmetrix better-sqlite3
bun add --dev @types/better-sqlite3
```

**2. Add the plugin**

```ts corsair.ts theme={null}
import Database from 'better-sqlite3';
import { createCorsair } from 'corsair';
import { gtmetrix } from '@corsair-dev/gtmetrix';

export const corsair = createCorsair({
	plugins: [
		gtmetrix(),
	],
	database: new Database('corsair.db'),
	kek: process.env.CORSAIR_KEK!,
	multiTenancy: true,
	hub: {
		projectApiKey: process.env.CORSAIR_API_KEY!,
		signingSecret: process.env.CORSAIR_SIGNING_SECRET!,
	},
});
```

With `multiTenancy: true`, scope calls with `corsair.withTenant(id)`. See [Quick start](https://docs.corsair.dev/quick-start.md) for KEK + Hub keys, and [Multi-tenancy](https://docs.corsair.dev/concepts/multi-tenancy.md) for account isolation.

**3. Choose authentication**

> [tab] API Key (Recommended)
>
> Store the GTmetrix API key before the first call: `pnpm corsair setup --plugin=gtmetrix --tenant=acme api_key=<your-key>` (leave out `--tenant` without `multiTenancy`), or pass it as `key` in the plugin options. With Hub, each tenant enters their own key on the connect page. See [API key auth](https://docs.corsair.dev/concepts/api-key).
>
> ```ts theme={null}
> gtmetrix()
> ```
>
> More: [API Key](https://docs.corsair.dev/concepts/api-key)

**4. Connect a tenant**

Mint a connect link and send the tenant to it. Hub hosts the page and delivers the result to your app — see [Connect / OAuth](https://docs.corsair.dev/management/connect).

```ts theme={null}
const { connectUrl } = await corsair.manage.connect.createLink({
	plugin: 'gtmetrix',
	tenantId: 'acme',
});
// redirect the user's browser to connectUrl
```

## Example API calls

**Read a report (grade, scores, Core Web Vitals)**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.gtmetrix.api.reports.get({ reportId: '<report id>' });
```

**Test a page (metrics only, 0.6 credits)**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.gtmetrix.api.tests.start({ url: 'https://example.com/', report: 'none' });
```

See the full list on the [API](https://docs.corsair.dev/plugins/gtmetrix/api.md) page.

## Query synced data

Synced entities support `tenant.gtmetrix.db.<entity>.search()` and `.list()`: `pages`, `reports`, `tags`, `tests`.

See [Database](https://docs.corsair.dev/plugins/gtmetrix/database.md) for filters and operators.

## What's next

> [card] [API reference](https://docs.corsair.dev/plugins/gtmetrix/api.md)
>
> Every `gtmetrix.api.*` operation with input and output types.

> [card] [Database](https://docs.corsair.dev/plugins/gtmetrix/database.md)
>
> Synced entities, search filters, and operators.

> [card] [Connect / OAuth](https://docs.corsair.dev/management/connect)
>
> createLink, Hub delivery, and tenant connect flows.

> [card] [Use with agents](https://docs.corsair.dev/mcp-adapters/mcp-adapters)
>
> Expose this plugin's operations as MCP tools.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.