SDKs and integrations
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));
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
| Option | Default | Does |
|---|---|---|
| accessKey | required | Your access key (shot_…). |
| secretKey | none | Secret key, needed only to sign URLs. Keep it on the server. |
| baseUrl | SHOTSMITH_BASE_URL or https://shotsmith.dev | API host. |
| timeoutMs | 120000 | Per-request timeout. Synchronous renders finish within 18 seconds; the extra headroom covers retries and slow networks. |
| maxRetries | 2 | Retries for rate limits, busy workers and network failures. |
| fetch | global fetch | Custom fetch, for tests or proxies. |
Methods
| Method | Returns |
|---|---|
| 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 / delete | Capture history |
| monitors.list / create / delete | Page 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
}
}