Official PHP SDK (v2.0.0) for SnapAPI — lightning-fast screenshot, PDF, scrape, extract, and AI web analysis API.
- PHP 8.0+
- ext-curl
- ext-json
composer require snapapi/sdk<?php
require 'vendor/autoload.php';
$api = new \SnapAPI\SnapAPI('your-api-key');
// Take a screenshot
$png = $api->screenshot([
'url' => 'https://example.com',
'format' => 'png',
]);
file_put_contents('screenshot.png', $png);Pass your API key to the constructor:
$api = new \SnapAPI\SnapAPI($_ENV['SNAPAPI_KEY']);// Basic PNG screenshot
$png = $api->screenshot([
'url' => 'https://example.com',
'format' => 'png',
'width' => 1440,
'height' => 900,
]);
// Full-page dark mode screenshot
$img = $api->screenshot([
'url' => 'https://example.com',
'fullPage' => true,
'darkMode' => true,
'blockAds' => true,
'blockCookieBanners' => true,
]);
// Screenshot from HTML
$img = $api->screenshotFromHtml('<h1 style="color:blue">Hello!</h1>');
// Screenshot from Markdown
$img = $api->screenshotFromMarkdown('# Title\n\nContent here.');
// With device emulation
$mobile = $api->screenshot([
'url' => 'https://example.com',
'device' => 'iphone-15-pro',
]);$pdf = $api->pdf([
'url' => 'https://example.com',
'pdf' => [
'pageSize' => 'A4',
'landscape' => false,
'marginTop' => '20px',
],
]);
file_put_contents('page.pdf', $pdf);
// PDF from HTML
$pdf = $api->pdf([
'html' => '<h1>Report</h1><p>Content</p>',
'pdf' => ['pageSize' => 'Letter'],
]);$result = $api->screenshotToStorage([
'url' => 'https://example.com',
'format' => 'png',
'storage' => ['destination' => 's3'],
]);
echo $result['url']; // Public S3 URL$result = $api->scrape([
'url' => 'https://example.com',
'type' => 'text', // text|html|links
'pages' => 3,
]);
foreach ($result['results'] as $page) {
echo "Page {$page['page']}: {$page['url']}\n";
echo substr($page['data'], 0, 100) . "...\n";
}// Article extraction
$article = $api->extractArticle('https://example.com/post');
// Markdown
$md = $api->extractMarkdown('https://example.com');
// Links
$links = $api->extractLinks('https://example.com');
// Images
$images = $api->extractImages('https://example.com');
// Metadata (title, description, OG tags…)
$meta = $api->extractMetadata('https://example.com');
// Structured data
$structured = $api->extractStructured('https://example.com');
// Full control
$result = $api->extract([
'url' => 'https://example.com',
'type' => 'article',
'includeImages' => true,
'maxLength' => 5000,
]);$result = $api->analyze([
'url' => 'https://example.com',
'prompt' => 'What is the main purpose of this page?',
'provider' => 'openai', // or 'anthropic'
'apiKey' => 'sk-...', // your LLM API key
'includeScreenshot' => true,
'includeMetadata' => true,
]);
echo $result['analysis'];// List files
$files = $api->listStorageFiles();
// Usage
$usage = $api->getStorageUsage();
echo "Used: {$usage['used']} / {$usage['limit']} bytes\n";
// Configure S3
$api->configureS3([
'bucket' => 'my-bucket',
'region' => 'us-east-1',
'accessKeyId' => 'AKIA...',
'secretAccessKey' => '...',
]);
// Delete a file
$api->deleteStorageFile('file-id');// Create hourly screenshot job
$job = $api->createScheduled([
'url' => 'https://example.com',
'cronExpression' => '0 * * * *',
'format' => 'png',
'fullPage' => true,
'webhookUrl' => 'https://myapp.com/webhook',
]);
echo $job['id'];
// List all jobs
$jobs = $api->listScheduled();
// Delete a job
$api->deleteScheduled($job['id']);// Create webhook
$hook = $api->createWebhook([
'url' => 'https://myapp.com/snapapi',
'events' => ['screenshot.completed', 'scheduled.run'],
'secret' => 'my-secret',
]);
// List
$hooks = $api->listWebhooks();
// Delete
$api->deleteWebhook($hook['id']);// List
$keys = $api->listKeys();
// Create
$key = $api->createKey('production');
echo $key['key']; // Only shown once
// Revoke
$api->deleteKey($key['id']);use SnapAPI\Exception\SnapAPIException;
try {
$img = $api->screenshot(['url' => 'https://example.com']);
} catch (SnapAPIException $e) {
echo $e->getErrorCode(); // e.g. "RATE_LIMITED"
echo $e->getStatusCode(); // e.g. 429
echo $e->getMessage(); // human-readable message
}SNAPAPI_KEY=your-key php examples/basic.phpMIT