| Crates.io | allscreenshots-sdk |
| lib.rs | allscreenshots-sdk |
| version | 0.1.0 |
| created_at | 2026-01-05 01:39:08.413494+00 |
| updated_at | 2026-01-05 01:39:08.413494+00 |
| description | Official Rust SDK for the Allscreenshots API - capture website screenshots programmatically |
| homepage | https://allscreenshots.com |
| repository | https://github.com/allscreenshots/allscreenshots-sdk-rust |
| max_upload_size | |
| id | 2022944 |
| size | 190,108 |
Official Rust SDK for the Allscreenshots API - capture website screenshots programmatically.
Add this to your Cargo.toml:
[dependencies]
allscreenshots-sdk = "0.1"
tokio = { version = "1", features = ["full"] }
use allscreenshots_sdk::{AllscreenshotsClient, ScreenshotRequest};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create client (reads API key from ALLSCREENSHOTS_API_KEY env var)
let client = AllscreenshotsClient::from_env()?;
// Take a screenshot
let request = ScreenshotRequest::builder()
.url("https://github.com")
.device("Desktop HD")
.build()?;
let image_bytes = client.screenshot(&request).await?;
std::fs::write("screenshot.png", &image_bytes)?;
println!("Screenshot saved to screenshot.png");
Ok(())
}
The SDK automatically reads the API key from the ALLSCREENSHOTS_API_KEY environment variable:
export ALLSCREENSHOTS_API_KEY=your-api-key
Configure the client with custom options:
use allscreenshots_sdk::AllscreenshotsClient;
use std::time::Duration;
let client = AllscreenshotsClient::builder()
.api_key("your-api-key")
.base_url("https://api.allscreenshots.com")
.timeout(Duration::from_secs(120))
.max_retries(5)
.build()?;
use allscreenshots_sdk::{AllscreenshotsClient, ScreenshotRequest, ImageFormat};
let client = AllscreenshotsClient::from_env()?;
let request = ScreenshotRequest::builder()
.url("https://example.com")
.device("Desktop HD")
.full_page(true)
.format(ImageFormat::Png)
.quality(90)
.dark_mode(true)
.build()?;
let image_bytes = client.screenshot(&request).await?;
std::fs::write("screenshot.png", &image_bytes)?;
For long-running screenshots, use the async API:
use allscreenshots_sdk::{AllscreenshotsClient, ScreenshotRequest};
use std::time::Duration;
let client = AllscreenshotsClient::from_env()?;
let request = ScreenshotRequest::builder()
.url("https://example.com")
.full_page(true)
.build()?;
// Start the job
let job = client.screenshot_async(&request).await?;
println!("Job created: {}", job.id);
// Poll for completion
loop {
let status = client.get_job(&job.id).await?;
if status.status.is_terminal() {
if status.status.is_success() {
let image = client.get_job_result(&job.id).await?;
std::fs::write("screenshot.png", &image)?;
println!("Screenshot saved!");
} else {
println!("Job failed: {:?}", status.error_message);
}
break;
}
tokio::time::sleep(Duration::from_secs(1)).await;
}
Capture multiple URLs in a single request:
use allscreenshots_sdk::{AllscreenshotsClient, BulkRequest, BulkUrlRequest, BulkDefaults};
let client = AllscreenshotsClient::from_env()?;
let request = BulkRequest::new(vec![
BulkUrlRequest::new("https://github.com"),
BulkUrlRequest::new("https://google.com"),
BulkUrlRequest::new("https://rust-lang.org"),
]).with_defaults(BulkDefaults {
device: Some("Desktop HD".to_string()),
..Default::default()
});
let bulk_job = client.create_bulk_job(&request).await?;
println!("Bulk job created: {}", bulk_job.id);
// Check status
let status = client.get_bulk_job(&bulk_job.id).await?;
println!("Progress: {}%", status.progress);
Combine multiple screenshots into a single image:
use allscreenshots_sdk::{
AllscreenshotsClient, ComposeRequest, CaptureItem,
ComposeOutputConfig, LayoutType
};
let client = AllscreenshotsClient::from_env()?;
let request = ComposeRequest::with_captures(vec![
CaptureItem::new("https://github.com").with_device("Desktop HD"),
CaptureItem::new("https://github.com").with_device("iPhone 14"),
CaptureItem::new("https://github.com").with_device("iPad"),
]).with_output(ComposeOutputConfig {
layout: Some(LayoutType::Horizontal),
spacing: Some(20),
background: Some("#ffffff".to_string()),
..Default::default()
});
let result = client.compose(&request).await?;
println!("Composed image URL: {:?}", result.url);
Set up recurring screenshot captures:
use allscreenshots_sdk::{AllscreenshotsClient, CreateScheduleRequest, ScheduleScreenshotOptions};
let client = AllscreenshotsClient::from_env()?;
let request = CreateScheduleRequest::new(
"Daily GitHub capture",
"https://github.com",
"0 9 * * *", // Every day at 9 AM
)
.with_timezone("America/New_York")
.with_retention_days(30)
.with_options(ScheduleScreenshotOptions {
device: Some("Desktop HD".to_string()),
full_page: Some(true),
..Default::default()
});
let schedule = client.create_schedule(&request).await?;
println!("Schedule created: {}", schedule.id);
// List all schedules
let schedules = client.list_schedules().await?;
for s in schedules.schedules {
println!(" {} - {}", s.name, s.status);
}
// Pause a schedule
client.pause_schedule(&schedule.id).await?;
// Resume a schedule
client.resume_schedule(&schedule.id).await?;
// Get execution history
let history = client.get_schedule_history(&schedule.id, Some(10)).await?;
for execution in history.executions {
println!(" {} - {}", execution.executed_at, execution.status);
}
Check your API usage:
use allscreenshots_sdk::AllscreenshotsClient;
let client = AllscreenshotsClient::from_env()?;
// Get usage statistics
let usage = client.get_usage().await?;
println!("Tier: {}", usage.tier);
println!("Screenshots this period: {}", usage.current_period.screenshots_count);
println!("Bandwidth used: {}", usage.current_period.bandwidth_formatted);
// Get quota status
let quota = client.get_quota().await?;
println!("Screenshots remaining: {}", quota.screenshots.remaining);
println!("Quota used: {}%", quota.screenshots.percent_used);
| Option | Type | Description |
|---|---|---|
url |
String |
Target URL to capture (required) |
device |
String |
Device preset (e.g., "Desktop HD", "iPhone 14", "iPad") |
viewport |
ViewportConfig |
Custom viewport dimensions |
format |
ImageFormat |
Output format: Png, Jpeg, Webp, Pdf |
full_page |
bool |
Capture the full scrollable page |
quality |
i32 |
Image quality (1-100, for JPEG/WebP) |
delay |
i32 |
Delay before capture in milliseconds (0-30000) |
wait_for |
String |
CSS selector to wait for |
wait_until |
WaitUntil |
Page load condition (Load, DomContentLoaded, NetworkIdle) |
timeout |
i32 |
Request timeout in milliseconds (1000-60000) |
dark_mode |
bool |
Enable dark mode |
custom_css |
String |
Custom CSS to inject |
hide_selectors |
Vec<String> |
CSS selectors to hide |
selector |
String |
Capture specific element |
block_ads |
bool |
Block advertisements |
block_cookie_banners |
bool |
Block cookie consent banners |
block_level |
BlockLevel |
Ad/tracker blocking level |
Common device presets:
| Device | Viewport |
|---|---|
| Desktop HD | 1920x1080 |
| Desktop | 1440x900 |
| Laptop | 1366x768 |
| iPhone 14 | 390x844 |
| iPhone 14 Pro Max | 430x932 |
| iPad | 820x1180 |
| iPad Pro | 1024x1366 |
The SDK provides typed errors for robust error handling:
use allscreenshots_sdk::{AllscreenshotsClient, ScreenshotRequest, AllscreenshotsError, ErrorCode};
let client = AllscreenshotsClient::from_env()?;
let request = ScreenshotRequest::builder()
.url("https://example.com")
.build()?;
match client.screenshot(&request).await {
Ok(image) => {
std::fs::write("screenshot.png", &image)?;
}
Err(AllscreenshotsError::ApiError { code, message, status }) => {
match code {
ErrorCode::RateLimitExceeded => {
println!("Rate limit exceeded, please wait and retry");
}
ErrorCode::Unauthorized => {
println!("Invalid API key");
}
ErrorCode::ValidationError => {
println!("Invalid request: {}", message);
}
_ => {
println!("API error ({}): {}", status, message);
}
}
}
Err(AllscreenshotsError::ValidationError(msg)) => {
println!("Request validation failed: {}", msg);
}
Err(AllscreenshotsError::Timeout) => {
println!("Request timed out");
}
Err(e) => {
println!("Error: {}", e);
}
}
The SDK automatically retries transient errors with exponential backoff:
Configure retry behavior:
let client = AllscreenshotsClient::builder()
.api_key("your-api-key")
.max_retries(5)
.build()?;
Apache License 2.0