API Documentation

Contents

Node.js SDK

The easiest way to use ShotAPI is with our official Node.js SDK. It provides full TypeScript support, automatic retries with exponential backoff, and convenient helper methods.

Installation

npm install @shotapi/sdk

Quick Start

import ShotAPI from '@shotapi/sdk';

const client = new ShotAPI({ apiKey: 'YOUR_API_KEY' });

// Basic screenshot
const result = await client.screenshot({
  url: 'https://example.com'
});

console.log(result.url); // URL to the screenshot

SDK Features

Full Page Screenshot
const result = await client.screenshot({
  url: 'https://example.com',
  fullPage: true
});
Device Preset
const result = await client.screenshot({
  url: 'https://example.com',
  device: 'iphone-14-pro'
});
Save to File
await client.screenshotToFile(
  { url: 'https://example.com' },
  './screenshot.png'
);
Get as Buffer
const buffer = await client.screenshotBuffer({
  url: 'https://example.com'
});
Batch Screenshots
const results = await client.batch([
  'https://example.com',
  'https://google.com'
], { width: 1280 });
Premium Features
const result = await client.screenshot({
  url: 'https://example.com',
  selector: '#hero',
  blockAds: true
});

Configuration

const client = new ShotAPI({
  apiKey: 'YOUR_API_KEY',  // Required
  baseUrl: 'https://shotapi.dev', // Optional
  timeout: 30000,          // Request timeout in ms (default: 30000)
  retries: 2               // Retry attempts (default: 2)
});

Error Handling

import ShotAPI, { ShotAPIException } from '@shotapi/sdk';

try {
  const result = await client.screenshot({ url: 'https://example.com' });
} catch (error) {
  if (error instanceof ShotAPIException) {
    console.error('API Error:', error.message);
    console.error('Error Code:', error.code);
    console.error('Status Code:', error.statusCode);
  }
}

View the full SDK documentation on npm or GitHub.

Authentication

All API requests require an API key. You can pass your API key in one of three ways:

  • Query parameter: ?api_key=YOUR_KEY
  • Header: X-API-Key: YOUR_KEY
  • Header: Authorization: Bearer YOUR_KEY

Screenshot Endpoint

GET/api/v1/screenshot
POST/api/v1/screenshot

Basic Parameters

ParameterTypeDefaultDescription
urlstringrequiredURL to capture
widthnumber1280Viewport width (320-3840)
heightnumber800Viewport height (240-2160)
full_pagebooleanfalseCapture full scrollable page
formatstringpngOutput format: png, jpeg, webp, pdf
qualitynumber90Image quality (1-100, jpeg/webp only)
delaynumber0Wait time in ms before capture (0-10000)
block_adsbooleanfalseBlock advertisements
block_cookie_bannersbooleantrueHide cookie consent popups
dark_modebooleanfalseEmulate dark mode preference
device_scale_factornumber1Device pixel ratio (1-3)

Example Request (GET)

curl "https://shotapi.dev/api/v1/screenshot?url=https://example.com&api_key=YOUR_KEY&width=1920&full_page=true"

Example Request (POST)

curl -X POST https://shotapi.dev/api/v1/screenshot \
  -H "X-API-Key: YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "width": 1920,
    "full_page": true,
    "device": "desktop",
    "dark_mode": true
  }'

Example Response

{
  "success": true,
  "data": {
    "screenshot_url": "https://r2.shotapi.dev/screenshots/abc123.png",
    "width": 1920,
    "height": 3200,
    "format": "png",
    "file_size": 524288,
    "cached": false
  },
  "usage": {
    "credits_used": 43,
    "credits_limit": 500,
    "credits_remaining": 457
  }
}

Premium Features

The following features are available on paid plans only. Free plan users will receive a 403 error when trying to use these features.

ParameterTypeDescription
devicestringDevice preset (desktop, mobile, tablet, iphone-14, etc.)
selectorstringCSS selector to capture specific element only
hide_selectorsstring[]CSS selectors of elements to hide (comma-separated for GET)
custom_cssstringCustom CSS to inject into the page (max 10KB)
custom_jsstringCustom JavaScript to execute (max 10KB)
wait_for_selectorstringWait for element before capture (10s timeout)
custom_headersobjectCustom HTTP headers (POST only)
user_agentstringCustom user agent string
thumbnailobjectGenerate thumbnail: {width, height}
extract_htmlbooleanInclude page HTML in response
clipobjectCrop region: {x, y, width, height}

Example: Capture Specific Element

curl -X POST https://shotapi.dev/api/v1/screenshot \
  -H "X-API-Key: YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "selector": "#main-content",
    "hide_selectors": [".ads", ".cookie-banner", ".popup"]
  }'

Example: Custom CSS Injection

curl -X POST https://shotapi.dev/api/v1/screenshot \
  -H "X-API-Key: YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "custom_css": "body { background: #f0f0f0; } .header { display: none; }"
  }'

Example: Generate Thumbnail

curl -X POST https://shotapi.dev/api/v1/screenshot \
  -H "X-API-Key: YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "thumbnail": { "width": 300, "height": 200 }
  }'

Response includes thumbnail_url in addition to the full screenshot.

PDF Generation

Generate PDF documents from any webpage by setting format=pdf.

Example Request

curl "https://shotapi.dev/api/v1/screenshot?url=https://example.com&format=pdf&api_key=YOUR_KEY"

PDF Response

{
  "success": true,
  "data": {
    "pdf_url": "https://r2.shotapi.dev/screenshots/abc123.pdf",
    "page_count": 3,
    "format": "pdf",
    "file_size": 156789
  },
  "usage": {
    "credits_used": 44,
    "credits_limit": 500,
    "credits_remaining": 456
  }
}

Device Presets

Use device presets to emulate common device viewports and user agents automatically.

PresetWidthHeightScaleMobile
desktop192010801xNo
laptop13667681xNo
tablet76810242xYes
tablet-landscape10247682xYes
mobile3758123xYes
mobile-landscape8123753xYes
iphone-143908443xYes
iphone-14-pro-max4309323xYes
ipad-pro102413662xYes
pixel-74129152.625xYes

Example: Mobile Screenshot

curl "https://shotapi.dev/api/v1/screenshot?url=https://example.com&device=iphone-14&api_key=YOUR_KEY"

Error Codes

CodeStatusDescription
MISSING_API_KEY401No API key provided
INVALID_API_KEY401API key is invalid or revoked
RATE_LIMIT_EXCEEDED429Too many requests
CREDITS_EXHAUSTED402Monthly credit limit reached
PREMIUM_REQUIRED403Feature requires paid plan
INVALID_URL400URL is invalid or not accessible
VALIDATION_ERROR400Invalid parameter value
SCREENSHOT_FAILED500Failed to capture screenshot

Rate Limits

PlanRequests/minScreenshots/monthPremium Features
Free10500No
Starter602,500Yes
Pro12010,000Yes
Business30050,000Yes

Ready to get started? Create a free account or upgrade your plan to unlock premium features.