Skip to content
shotsmith
Features Docs Guides Pricing Changelog Sign inStart free

Node SDK

The official SDK for Node 18+, Bun, Deno and edge runtimes. It has no dependencies (it uses fetch and Web Crypto), typed options for every API option, request signing, automatic retries and webhook verification.

Install

npm install @shotsmith/sdk

Take a screenshot

// npm install @shotsmith/sdk
import { Shotsmith, TakeOptions } from '@shotsmith/sdk';
import { writeFile } from 'node:fs/promises';

const shotsmith = new Shotsmith({
  accessKey: 'YOUR_ACCESS_KEY',
});

const options = TakeOptions.url('https://shotsmith.dev/sample')
  .fullPage()
  .blockCookieBanners()
  .format('webp');

await writeFile('capture.webp', await shotsmith.take(options));
Response 200 OK
Content-Type: image/webp
X-Capture-Id: 01m8kvpk6jsmeykdfs0wy6awbn
X-Cache: MISS
X-Render-Time: 296
X-Quota-Limit: 15000
X-Quota-Remaining: 14998
X-RateLimit-Limit: 80
X-RateLimit-Remaining: 79
(the WebP image: take() resolves to its bytes as a Uint8Array, written to capture.webp)

Options can be a builder, as above, or a plain object with the API’s names: shotsmith.take({ url, full_page: true }). Every option in the option reference has a builder method, named in camelCase.

Configuration

OptionDefaultDoes
accessKeyrequiredYour access key (shot_…).
secretKeynoneSecret key, needed only to sign URLs. Keep it on the server.
baseUrlSHOTSMITH_BASE_URL or https://shotsmith.devAPI host.
timeoutMs120000Per-request timeout. Synchronous renders finish within 18 seconds; the extra headroom covers retries and slow networks.
maxRetries2Retries for rate limits, busy workers and network failures.
fetchglobal fetchCustom fetch, for tests or proxies.

Methods

MethodReturns
take(options)The file’s bytes (Uint8Array)
takeWithInfo(options)Bytes plus capture ID, cache hit, render time and quota left
takeJson(options)The capture as JSON: file URL, metadata, vision answer (example)
takeAsync(options) / waitFor(id)Queue a render, then poll until it’s done (example)
animate(options)A scrolling video or GIF (example)
generateTakeUrl(options)A signed URL for an <img> tag (example)
bulk(requests, { options, execute })Up to 100 captures (example)
captures.get / list / deleteCapture history
monitors.list / create / deletePage monitors (example)
usage(), devices(), countries()Account and reference data
Shotsmith.verifyWebhook(body, signature, secret)true if a webhook’s signature is valid
Shotsmith.parseWebhook(body, signature, secret)The parsed event; throws if the signature is wrong (example)

Errors

Failed calls throw ShotsmithError with the API’s code, the HTTP status, per-option details for validation errors, and captureId when a capture was created. Rate limits (429) and busy workers (503) are retried automatically, honouring Retry-After. Quota and validation errors are not retried. See Errors for every code.

import { ShotsmithError } from '@shotsmith/sdk';

try {
  await shotsmith.take({ url: 'https://shotsmith.dev/sample', selector: '#newsletter-signup' });
} catch (err) {
  if (err instanceof ShotsmithError && err.code === 'selector_not_found') {
    // fall back to a viewport screenshot
  }
}