# Ghost Gateway (`straightforward_understanding/ghost-gateway`) Actor

- **URL**: https://apify.com/straightforward\_understanding/ghost-gateway.md
- **Developed by:** [Yann Feunteun](https://apify.com/straightforward_understanding) (community)
- **Categories:** Other
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $30.00 / 1,000 browser minutes

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

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

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Ghost Gateway

One URL that hands you an isolated, stealth Chromium over the Chrome DevTools Protocol.

Ghost Gateway is a **standby Actor**: it is always addressable at a single HTTPS endpoint, and each
client connection gets its own browser. The gateway itself runs no browser — it allocates one in a
separate Actor run, fetches that browser's real CDP endpoint, and splices the websocket through to
you. You drive it with any CDP client: Playwright, Puppeteer, chrome-remote-interface, or raw
websocket.

Browsers are billed per session and per minute held, so an idle integration costs nothing.

### Quick start

Every request needs your Apify API token.

```bash
GATEWAY=https://<username>--ghost-gateway.apify.actor

## 1. mint a session
curl -X POST "$GATEWAY/v1/sessions" \
  -H "authorization: Bearer $APIFY_TOKEN" \
  -H 'content-type: application/json' -d '{}'
## -> {"session":"7bd58f05-…","rev":0}

## 2. get a browser and its CDP websocket
curl "$GATEWAY/json/version" -H "authorization: Bearer $APIFY_TOKEN"
## -> {"Browser":"Chrome/149…","webSocketDebuggerUrl":"wss://…/devtools/browser/…"}
```

Then connect with your CDP client of choice:

```js
import { chromium } from 'playwright';

const browser = await chromium.connectOverCDP(webSocketDebuggerUrl);
const page = await browser.newPage();
await page.goto('https://example.com/');
console.log(await page.title());
await browser.close();   // releasing the connection releases the browser
```

Closing the websocket releases the browser and stops the per-minute charge.

### Sessions

A session is durable identity — cookies, storage, and a pinned proxy exit — that outlives any one
browser. Allocate a browser against a session, drive it, release it, and allocate another later: the
second browser resumes the first one's identity. A session is not itself a billing entity; only live
browsers are.

| Route | Method | Purpose |
|---|---|---|
| `/v1/sessions` | POST | Mint a session. Returns `{session, rev}`. |
| `/v1/sessions/:session` | GET | Snapshot of the session's stored state. |
| `/v1/sessions/:session/commit` | POST | Commit cookies/storage back into the session. |
| `/v1/sessions/:session/browser` | POST | Allocate a live browser for the session. |
| `/v1/sessions/:session/proxy` | GET | Read the session's current proxy lease. |
| `/v1/sessions/:session/proxy/acquire` | POST | Take a proxy lease. |
| `/v1/sessions/:session/proxy/rotate` | POST | Rotate to a new exit IP. |
| `/v1/sessions/:session/mutation-lease` | POST | Take a write lease, so concurrent writers don't clobber each other. |
| `/v1/sessions/:session/mutation-lease/renew` | POST | Renew a held write lease. |
| `/v1/sessions/:session/mutation-lease/release` | POST | Release a write lease. |
| `/json/version`, `/json/list` | GET | CDP discovery. `webSocketDebuggerUrl` points back at the gateway. |

Session ids are scoped to the caller — you only ever see your own.

### Geography

Browsers egress through residential proxies. A session's exit country is pinned when its proxy lease
is taken, and the browser's persona is made to agree with it: `Accept-Language`, the page's language
list, `Intl` locale, and timezone all match the exit rather than contradicting it.

Not every country is available; an unsupported one is refused at allocation rather than silently
served from somewhere else.

### Notes

- **Cold starts.** With no warm pool configured, the first browser of a session waits for a fresh
  browser Actor to start. Expect tens of seconds. Subsequent allocations against a warm gateway are
  much faster.
- **Timeouts.** Idle sessions and unclaimed browsers are reaped automatically, so a client that
  disappears does not leave a browser billing.
- **Errors.** `401` means no or invalid token. `404 no_session` means the session id was never
  minted, or not by you. `402` means a browser was allocated but could not be charged, and was
  released rather than handed over.

# Actor input Schema

## Actor input object example

```json
{}
```

# Actor output Schema

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("straightforward_understanding/ghost-gateway").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 = {}

# Run the Actor and wait for it to finish
run = client.actor("straightforward_understanding/ghost-gateway").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 '{}' |
apify call straightforward_understanding/ghost-gateway --silent --output-dataset

```

## MCP server setup

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

```

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/tRRu5AFTbA7rNZuGO/builds/N1DAwAP9OSN9vV0xW/openapi.json
