Skip to main content
published reference

Based on the published Legba skill. Verified 2026-10-28. Requests require your API key and available plan capacity.

Integration cookbook

Use the published clients and HTTP API for complete tasks, including cleanup and human handoff.

Before you run a recipe

Install the skill and configure LEGBA_API_KEY. Set SKILL to its installation directory.

export SKILL='/absolute/path/to/legba'
node "$SKILL/scripts/legba-session.mjs" current

Inspect existing work before creating a session. Reuse only a session appropriate for your task. Hosted recipes require an eligible paid plan.

A complete HTTP browser task

Save this as legba-read.mjs. Run it with Node.js and your environment key. It checks current state before creating a browser.

Navigation and reading retry the documented startup failures. Cleanup ends the created session, even after an error. The script prints page text without printing session URLs.

const base = "https://skill.legba.xyz/api/v1";
const key = process.env.LEGBA_API_KEY;
if (!key) throw new Error("Set LEGBA_API_KEY before running.");

async function request(path, method = "GET", body) {
  const response = await fetch(base + path, {
    method,
    headers: {
      Authorization: "Bearer " + key,
      "Content-Type": "application/json",
    },
    body: body === undefined ? undefined : JSON.stringify(body),
  });
  const raw = await response.text();
  let data;
  try { data = JSON.parse(raw); } catch { data = raw; }
  if (!response.ok) {
    const error = new Error(JSON.stringify(data?.detail ?? data));
    error.status = response.status;
    throw error;
  }
  return data;
}

const current = await request("/sessions/current");
if (current.session) {
  throw new Error("A session already exists. Inspect it before continuing.");
}

let session;
try {
  session = await request("/sessions", "POST", {
    kind: "browser", country: "US", browser: "agent",
  });
  const browserPath = "/sessions/" + encodeURIComponent(session.id) + "/browser/";
  async function readyAction(action, body) {
    const deadline = Date.now() + 150_000;
    for (;;) {
      try { return await request(browserPath + action, "POST", body); }
      catch (error) {
        const startup = [502, 503, 504].includes(error.status)
          || /still starting|bridge_unreachable|not answering/.test(error.message);
        if (error.status === 402 || !startup || Date.now() >= deadline) throw error;
        await new Promise(resolve => setTimeout(resolve, 5000));
      }
    }
  }
  await readyAction("navigate", { url: "https://example.com" });
  const page = await readyAction("read", {});
  console.log(page.title);
  console.log(page.text);
} finally {
  if (session?.id) {
    await request("/sessions/" + encodeURIComponent(session.id), "DELETE");
  }
}
node legba-read.mjs

If creation fails with an uncertain network outcome, inspect current state. Do not blindly repeat the creation request. If cleanup fails, inspect and end your session explicitly.

Render a page locally

Install Playwright and its Chromium browser once. These commands run inside the skill's scripts directory.

cd "$SKILL/scripts"
pnpm add playwright
pnpm exec playwright install chromium

Start a routing session with the session client. Copy its returned PROXY_URL into your shell. Render the page through that same route:

node "$SKILL/scripts/legba-session.mjs" start --kind proxy --country US
PROXY_URL='PASTE_RETURNED_PROXY_URL'
node "$SKILL/scripts/render.mjs" https://example.com \
  --proxy "$PROXY_URL" --out page.html --screenshot page.png
node "$SKILL/scripts/legba-session.mjs" end

End the routing session even when rendering fails. The local renderer does not own a route supplied through --proxy.

For the local Firefox client, install Camoufox first. Start a fresh routing session for this separate recipe:

python3 -m pip install --user 'camoufox[geoip]'
python3 -m camoufox fetch
node "$SKILL/scripts/legba-session.mjs" start --kind proxy --country US
PROXY_URL='PASTE_RETURNED_PROXY_URL'
python3 "$SKILL/scripts/antibot.py" https://example.com \
  --proxy "$PROXY_URL" --out page.html
node "$SKILL/scripts/legba-session.mjs" end

This browser runs on your machine. If installation or startup is unavailable, check hosted-plan eligibility. Do not repeat an installation your environment cannot support.

Continue after a human step

Start an agent browser and navigate to your page. Hand over whenever personal authentication is required.

node "$SKILL/scripts/legba-session.mjs" start --kind browser --country US
node "$SKILL/scripts/legba-session.mjs" go https://example.com
node "$SKILL/scripts/legba-session.mjs" handoff --reason "Please complete the sign-in step."

Give the printed VIEW_URL to the intended person. Explain the step they need to complete. Wait for them to finish in that same browser.

node "$SKILL/scripts/legba-session.mjs" wait-for-human --timeout 300
# Inspect the result before continuing. A timeout is not completion.
# Run resume only after the person has finished:
node "$SKILL/scripts/legba-session.mjs" resume
node "$SKILL/scripts/legba-session.mjs" read --out page.txt
node "$SKILL/scripts/legba-session.mjs" end

timed_out: true means human control remains active. An ended state means the session no longer exists. Handle both before attempting to resume.

Save a hosted screenshot

With an agent browser already running, capture a PNG:

node "$SKILL/scripts/legba-session.mjs" shot --full --out page.png

The client decodes the API's png_base64 response. Use read --out page.txt for page text. The read action does not return raw HTML.

Existing routing-pool integrations

The repository also includes legba-proxy.mjs. It exposes get, fetch, cleanup, health, rotate, refresh, release, mine, and locations.

This helper uses the legacy pool's X-API-Key header. Its paths sit outside /api/v1. Do not mix pool IDs with session IDs.

node "$SKILL/scripts/legba-proxy.mjs" locations
node "$SKILL/scripts/legba-proxy.mjs" get --country US --mode wireguard --client-id my-task
# Use the returned route, then release this task's allocation:
node "$SKILL/scripts/legba-proxy.mjs" cleanup --client-id my-task

Pool options include --sticky and --ttl-days. Read the published pool client before extending an existing integration.

For a new task, use the session lifecycle first.