ScreenshotNeo

BlogHow-to

LambdaTest Screenshot API Setup in Node.js for Indian Developers

Start a LambdaTest cross-browser screenshot job from Node.js, retrieve its results, and handle credentials, configuration, polling, and common errors.

By the ScreenshotNeo team4 October 20268 min read

To set up the LambdaTest Screenshot API in Node.js, send an authenticated JSON POST request to https://api.lambdatest.com/screenshots/v1/, save the returned test_id, then request GET https://api.lambdatest.com/screenshots/v1/{test_id} to retrieve status and screenshot records. The examples below use Node.js’s built-in fetch; the official references document the HTTP API, not a complete Node.js SDK tutorial. This general workflow applies to developers in India too: the reviewed sources document no India-specific endpoint or credential flow. [Start Screenshot Test API] [Fetch Screenshot Details API]

1. Get credentials and prepare Node.js

LambdaTest (now TestMu AI in some official documentation) uses your account username and access key for HTTP Basic authentication. The setup guide says to find these in the account dashboard and store them as LT_USERNAME and LT_ACCESS_KEY environment variables. Never commit credentials to source control or paste them into a shared log. [LambdaTest environment variables setup]

# macOS / Linux, for the current shell
export LT_USERNAME='your_username'
export LT_ACCESS_KEY='your_access_key'
node --version

The code uses top-level await, available in modern Node.js ES modules. Save it as lambdatest-shot.mjs and run node lambdatest-shot.mjs. If your project uses CommonJS, put the code inside an async function main() { ... } and call main().catch(console.error). Check your Node.js version supports built-in fetch; otherwise upgrade or use your project’s approved HTTP client.

2. Start a screenshot test

This minimal request shows the documented endpoint, Basic auth, JSON body, and test_id response. The browser configurations below are intentionally a placeholder: choose OS, browser, and version combinations currently available in your LambdaTest account or current documentation. The vendor’s examples include legacy versions and are not a current support matrix. [Start Screenshot Test API] [Automated Screenshot Testing setup]

const username = process.env.LT_USERNAME;
const accessKey = process.env.LT_ACCESS_KEY;

if (!username || !accessKey) {
  throw new Error('Set LT_USERNAME and LT_ACCESS_KEY before running this script.');
}

const authorization = Buffer.from(`${username}:${accessKey}`).toString('base64');
const apiBase = 'https://api.lambdatest.com/screenshots/v1';
const payload = {
  url: 'https://example.com',
  defer_time: 0,
  email: false,
  win_res: '1366x768',
  configs: {
    // Add browser/OS/version entries supported by your current account.
  },
};

const response = await fetch(`${apiBase}/`, {
  method: 'POST',
  headers: {
    Authorization: `Basic ${authorization}`,
    'Content-Type': 'application/json',
    Accept: 'application/json',
  },
  body: JSON.stringify(payload),
});

if (!response.ok) {
  const detail = await response.text();
  throw new Error(`Start request failed (HTTP ${response.status}): ${detail}`);
}

const started = await response.json();
if (!started.test_id) {
  throw new Error(`Response did not include test_id: ${JSON.stringify(started)}`);
}

console.log('Screenshot test started:', started.test_id);

The payload’s url selects the page to capture. The API reference lists fields including defer_time, email, mac_res, win_res, tunnel, tunnel_identifier, username, password, callback_url, and configs. Use only fields needed for your run and validate their current schema in the API reference. [Start Screenshot Test API]

3. Retrieve test status and screenshot URLs

Use the returned ID in the details endpoint. A screenshot record can include the OS, browser, browser version, resolution, status, screenshot URL, thumbnail URL, and activity ID. The examples in the vendor response are illustrative; verify current browser/version support before relying on any specific combination. [Fetch Screenshot Details API]

const testId = started.test_id;
const detailsResponse = await fetch(
  `${apiBase}/${encodeURIComponent(testId)}`,
  { headers: { Authorization: `Basic ${authorization}`, Accept: 'application/json' } },
);

if (!detailsResponse.ok) {
  const detail = await detailsResponse.text();
  throw new Error(`Details request failed (HTTP ${detailsResponse.status}): ${detail}`);
}

const details = await detailsResponse.json();
console.log('Test status:', details.test_status);
for (const shot of details.screenshots ?? []) {
  console.log({
    os: shot.os,
    browser: shot.browser,
    version: shot.browser_version,
    resolution: shot.resolution,
    status: shot.status,
    screenshotUrl: shot.screenshot_url,
    thumbnailUrl: shot.thumbnail_url,
  });
}

The reference establishes the details endpoint and response fields, but does not prescribe a polling interval or completion time. If the result is not ready on the first retrieval, use bounded retries with a delay that grows between attempts, stop after a limit, and surface the last status rather than looping indefinitely. Alternatively, the start request reference lists callback_url; use a callback when your application can receive it, and follow the current vendor guidance for callback delivery and verification.

4. cURL, Python, and Node.js request patterns

These equivalent starts are useful for separating credential or payload problems from application code. Replace the sample URL and configuration with values valid for your account. Do not put real secrets into scripts committed to a repository.

cURL

curl --user "$LT_USERNAME:$LT_ACCESS_KEY" \
  --header 'Content-Type: application/json' \
  --header 'Accept: application/json' \
  --data '{"url":"https://example.com","defer_time":0,"email":false,"win_res":"1366x768","configs":{}}' \
  'https://api.lambdatest.com/screenshots/v1/'

Python

import json
import os
import urllib.error
import urllib.request

username = os.environ["LT_USERNAME"]
access_key = os.environ["LT_ACCESS_KEY"]
credentials = f"{username}:{access_key}".encode()
import base64
authorization = "Basic " + base64.b64encode(credentials).decode()

payload = {
    "url": "https://example.com",
    "defer_time": 0,
    "email": False,
    "win_res": "1366x768",
    "configs": {},  # Add currently supported browser/OS/version entries.
}
request = urllib.request.Request(
    "https://api.lambdatest.com/screenshots/v1/",
    data=json.dumps(payload).encode(),
    headers={
        "Authorization": authorization,
        "Content-Type": "application/json",
        "Accept": "application/json",
    },
    method="POST",
)
try:
    with urllib.request.urlopen(request, timeout=60) as response:
        result = json.load(response)
    print("test_id:", result["test_id"])
except urllib.error.HTTPError as error:
    print("HTTP error:", error.code, error.read().decode())
    raise

For production Python code, use your team’s standard HTTP library and explicit timeout and retry policy. The example uses only the standard library.

5. Choose configuration for the job

Need Relevant API fields or approach What to check
Target page url It must be reachable from the hosted screenshot environment.
Browser/OS coverage configs Use the current supported combinations; do not copy old example versions blindly.
Viewport resolution win_res, mac_res Choose the resolution relevant to the page layout and supported by the chosen configuration.
Delay before capture defer_time Allow client-rendered content time to settle; avoid large delays unless the page requires them.
Private or local target tunnel, tunnel_identifier These fields exist in the reference. Follow current tunnel setup instructions separately; the fields alone are not a full local-network recipe.
Completion notification callback_url Use only if you have a reachable receiver and have accounted for callback security and retries.
Email notifications email Set according to the workflow’s notification needs.

The broader API reference also lists operations for available OS/browser combinations, devices, resolutions, locations, and starting or stopping tests. Consult the current reference or account tools for actual availability; the reviewed material does not establish current regional performance, pricing, or a benchmark.

6. Handle failures, speed, and operating cost

Common errors and fixes

Symptom Likely cause Fix
Missing environment variable error The process cannot see one or both credentials. Export LT_USERNAME and LT_ACCESS_KEY in the shell or runtime environment that launches Node.
HTTP 401 or 403 Credentials are wrong, stale, or belong to an account without access. Recheck the dashboard values and account access; do not print the access key into logs.
HTTP 400 Malformed JSON, invalid field, or unsupported browser configuration. Read the response body, reduce to the minimal payload, and check current API schema and browser availability.
HTTP 404 on details The ID is incorrect, URL-encoded incorrectly, or not associated with the account. Pass the exact returned test_id through encodeURIComponent and verify it was saved without truncation.
Test remains pending or incomplete The capture is still processing or the target is slow/unreachable. Retrieve details again with bounded backoff; check target accessibility and avoid assuming a fixed completion time.
No expected page content The page depends on client rendering, authentication, or network access unavailable to the capture. Adjust documented defer or access settings, confirm the page can be reached in the hosted environment, and inspect the returned status.
Network timeout Local network restrictions, transient service/network issue, or a slow response. Check outbound HTTPS access, set an application timeout suitable for the request, and retry transient failures with a strict cap.

Performance and reliability

  • Request only the browser/OS combinations and resolutions needed for the check; a larger matrix naturally means more capture work to wait for and process.
  • For dynamic pages, set a reasonable defer_time or use the callback workflow instead of repeatedly making rapid detail requests.
  • Persist the test_id before handing work to another process so a restart does not lose the handle.
  • Use bounded retries for transient HTTP failures and pending results. Avoid retrying permanent authentication or validation errors unchanged.
  • For private targets, configure a supported tunnel using current instructions; merely setting tunnel fields may not be enough.

Cost and India-specific considerations

The reviewed official sources do not provide a current price, usage quota, India-specific pricing, or regional performance guarantee. Check commercial terms in your account before estimating cost. For Indian deployments, the API workflow remains the documented general endpoint and authentication pattern; check your organization’s outbound network policy, account access, and any applicable data-handling requirements. Do not infer a regional endpoint or local availability from the audience location.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server from Yorker Media. For a direct screenshot, use one GET request; see the API documentation for options:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
  • Cookie banners are accepted and removed before capture, and known consent platforms, newsletter popups, and chat widgets can be removed; each step can be disabled.
  • Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed. Response headers identify the page verdict and billing status.
  • An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.
  • The free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 screenshots; every feature is available on every plan.

Sign up for ScreenshotNeo free: 1,000 screenshots a month, no card required.

FAQ

How do I set up the LambdaTest Screenshot API in Node.js?

Store the account username and access key in environment variables, POST JSON with Basic authentication to the screenshot endpoint, and use the returned test_id to fetch result details.

How do I capture cross-browser screenshots with LambdaTest from Node.js?

Provide the target URL and supported browser/OS entries in configs, start the test, then retrieve the screenshot records by ID. Check current browser availability before pinning versions.

Does the API work differently for Indian developers?

The reviewed official sources document no India-specific setup difference. Use the standard endpoint and credentials, and check your account and network policies for deployment-specific constraints.

Is there an official Node.js SDK example in the cited material?

No complete Node.js SDK tutorial was found in the reviewed official references. The JavaScript snippets here apply the documented REST contract using built-in Node.js fetch.