Documentation 3 min read

Screenshot API

The Screenshot API captures full-page screenshots of web pages in either desktop or mobile viewports, returning the image directly in the response.


Authentication

All API requests require authentication. Include your API key in the request header:

X-API-Key: your_api_key_here

Production Endpoints

GET /api/v1/screenshot/{domain}

GET /api/v1/screenshot?url={url}

Parameters

Parameter Type Required Description
domain string Conditional The domain name of the website to screenshot (e.g., example.com). Required if url is not provided.
url string Conditional A full URL to screenshot (e.g., https://www.example.com/page). Required if domain is not provided. Must include http:// or https://.
mobile boolean No Set to true to capture a mobile viewport (simulating an iPhone). Defaults to false (desktop).

Response Field Descriptions

The API returns the screenshot as an image file directly in the response body. The Content-Type header will be image/png.

No JSON response is provided for successful screenshot captures. In case of an error, a JSON error object will be returned.


Example Response (Success)

A successful request will return a PNG image. The Content-Type header will be image/png.

<binary image data>

Examples

cURL (Desktop Screenshot)

curl -X GET "https://api.chapyapi.com/api/v1/screenshot/example.com" \
  -H "X-API-Key: your_api_key_here" \
  -o example_screenshot_desktop.png

cURL (Mobile Screenshot)

curl -X GET "https://api.chapyapi.com/api/v1/screenshot?url=https://www.github.com/devAlphaSystem&mobile=true" \
  -H "X-API-Key: your_api_key_here" \
  -o github_screenshot_mobile.png

JavaScript

const apiKey = 'your_api_key_here';

async function fetchScreenshot(target, isMobile = false) {
  const isUrl = target.startsWith('http://') || target.startsWith('https://');
  let endpoint = isUrl ? `/api/v1/screenshot?url=${encodeURIComponent(target)}` : `/api/v1/screenshot/${target}`;
  
  if (isMobile) {
    endpoint += isUrl ? '&mobile=true' : '?mobile=true';
  }

  const response = await fetch(`https://api.chapyapi.com${endpoint}`, {
    headers: {
      'X-API-Key': apiKey
    }
  });

  if (response.ok) {
    const blob = await response.blob();
    const imageUrl = URL.createObjectURL(blob);
    console.log('Screenshot URL:', imageUrl);
    // You can display this image in an <img> tag or download it
    // Example: document.getElementById('screenshotImage').src = imageUrl;
  } else {
    const errorData = await response.json();
    console.error('Error fetching screenshot:', errorData);
  }
}

// Get desktop screenshot
fetchScreenshot('example.com');
// Get mobile screenshot
fetchScreenshot('https://www.github.com/devAlphaSystem', true);

Python

import requests

api_key = "your_api_key_here"

def fetch_screenshot(target, filename, is_mobile=False):
    params = {}
    if target.startswith('http://') or target.startswith('https://'):
        url = f"https://api.chapyapi.com/api/v1/screenshot"
        params['url'] = target
    else:
        url = f"https://api.chapyapi.com/api/v1/screenshot/{target}"
    
    if is_mobile:
        params['mobile'] = 'true'

    headers = {"X-API-Key": api_key}
    response = requests.get(url, headers=headers, params=params)

    if response.status_code == 200:
        with open(filename, 'wb') as f:
            f.write(response.content)
        print(f"Screenshot saved to {filename}")
    else:
        print(f"Error fetching screenshot: {response.status_code}")
        print(response.json())

# Get desktop screenshot
fetch_screenshot("example.com", "example_desktop.png")
# Get mobile screenshot
fetch_screenshot("https://www.github.com/devAlphaSystem", "github_mobile.png", is_mobile=True)

Error Handling

The API uses standard HTTP status codes and returns error details in JSON format.

Status Code Error Code Description
400 VALIDATION_ERROR Invalid domain or URL format provided.
401 MISSING_API_KEY API key not provided.
401 INVALID_API_KEY API key is invalid, inactive, or expired.
402 QUOTA_EXCEEDED Your daily screenshot request quota has been reached.
403 ENDPOINT_FORBIDDEN Your API key is not permitted to access this endpoint.
403 FORBIDDEN Access to private/reserved/local IPs is blocked (SSRF protection).
429 RATE_LIMIT_EXCEEDED Too many requests. Check X-RateLimit-Reset header.
503 SERVICE_INITIALIZING The service is starting up. Please try again shortly.
503 SERVICE_ERROR Failed to capture the screenshot (e.g., page timed out, browser error).

Error Response Example

{
  "error": "Failed to capture screenshot: Navigation timeout of 30000 ms exceeded.",
  "code": "SERVICE_ERROR",
  "requestId": "req_1755376547140_e2d4a023"
}