> ## 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.

# ngrok plugin

> Manage ngrok cloud endpoints and their traffic policies, reserve custom domains, list agent tunnels and API keys, and manage event subscriptions that deliver ngrok events to your destinations.

Use **ngrok** through Corsair: one client, typed API calls.

Create an API key at [https://dashboard.ngrok.com/api-keys](https://dashboard.ngrok.com/api-keys). The plugin sends it as a bearer token and also sends the `Ngrok-Version: 2` header every request needs; without that header the API answers a version error that reads like an auth failure.

Things worth knowing:

* **`url` is the endpoint's own address, not an upstream.** Use a domain the account owns, such as the free `*.ngrok-free.dev` dev domain. Where requests go is decided by the Traffic Policy.
* **A cloud endpoint needs a Traffic Policy.** ngrok answers 400 `ERR_NGROK_18015` without one, and the policy has to end in a terminal action such as `forward-internal`, `redirect` or `custom-response`. It is text (YAML or JSON), not an object.
* **Creating an endpoint makes it live.** It serves on its URL as soon as `endpoints.create` returns.
* **Reserving a domain needs a paid plan** (free accounts get `ERR_NGROK_401`; they have one dev domain with `is_dev: true` and a null `cname_target`).
* **Reserving a domain does not make it serve traffic.** `domains.create` returns a `cname_target`; point DNS at it, and certificate issuance starts once the record resolves. `certificate_management_status.provisioning_job` reports how that went.
* **An API key's token is returned once.** `apiKeys.create` includes the `token` in its response and never again; a later `apiKeys.list` or read omits it. Store it when it is minted, because there is no way to read it back.
* **Paging is by id, not page number.** A list answers `next_page_uri`, the full URL of the next page, or null on the last page. Pass that URL, or the `before_id` value in its query, as `before_id`; the plugin sends only the id. Keep the same `limit` and `filter`.
* **Event subscriptions need destinations that already exist.** `events.create` takes `destination_ids`, and destinations are created through a separate ngrok API that this plugin does not wrap.

Errors carry a globally unique code, and two of them share a 403: `ERR_NGROK_200` means no Authorization header was sent, while `ERR_NGROK_202` means the credential does not look like a key. The plugin reports both as auth failures, and keeps the `operation_id` that ngrok support asks for. A 5xx on a read is retried; a 5xx on a create, update or delete is not, because it may have gone through.

**What you get:**

* 18 typed API operations

## Setup

**1. Install**

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

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

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

```bash bun theme={null}
bun add corsair @corsair-dev/ngrok 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 { ngrok } from '@corsair-dev/ngrok';

export const corsair = createCorsair({
	plugins: [
		ngrok(),
	],
	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 ngrok API key before the first call: `pnpm corsair setup --plugin=ngrok --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}
> ngrok()
> ```
>
> 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: 'ngrok',
	tenantId: 'acme',
});
// redirect the user's browser to connectUrl
```

## Example API calls

**List the first endpoints**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.ngrok.api.endpoints.list({ limit: 10 });
```

**Reserve a custom domain**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.ngrok.api.domains.create({ domain: 'acme.example.com', description: 'Acme production' });
```

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

## What's next

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

> [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.