SDKs
.NET SDK
.NET 8.0+ compatible SDK
.NET SDK
The official .NET SDK for the AllScreenshots API. Requires .NET 8.0 or later.
Source code: GitHub | Package: AllScreenshots.Sdk
Installation
dotnet add package AllScreenshots.SdkOr via Package Manager Console:
Install-Package AllScreenshots.SdkQuick start
using AllScreenshots.Sdk;
using AllScreenshots.Sdk.Models;
// Create client (reads API key from ALLSCREENSHOTS_API_KEY environment variable)
using var client = new AllScreenshotsClient();
// Take a screenshot
var imageBytes = await client.Screenshots.CaptureAsync(new ScreenshotRequest
{
Url = "https://github.com",
Device = "Desktop HD"
});
// Save to file
File.WriteAllBytes("screenshot.png", imageBytes);Configuration
Direct configuration
using var client = new AllScreenshotsClient(new AllScreenshotsOptions
{
ApiKey = "your-api-key",
BaseUrl = "https://api.allscreenshots.com",
Timeout = TimeSpan.FromSeconds(60),
MaxRetries = 3
});Environment variables
Set ALLSCREENSHOTS_API_KEY to automatically configure authentication:
// Client will read API key from environment
using var client = new AllScreenshotsClient();Capture screenshots
Basic capture
var imageBytes = await client.Screenshots.CaptureAsync(new ScreenshotRequest
{
Url = "https://example.com"
});
File.WriteAllBytes("screenshot.png", imageBytes);With options
var imageBytes = await client.Screenshots.CaptureAsync(new ScreenshotRequest
{
Url = "https://example.com",
Device = "Desktop HD",
Format = "png",
FullPage = true,
DarkMode = true,
BlockAds = true,
BlockCookieBanners = true,
Delay = 1000
});Device presets
// Desktop
var desktop = await client.Screenshots.CaptureAsync(new ScreenshotRequest
{
Url = "https://example.com",
Device = "Desktop HD"
});
// Mobile
var mobile = await client.Screenshots.CaptureAsync(new ScreenshotRequest
{
Url = "https://example.com",
Device = "iPhone 15"
});
// Tablet
var tablet = await client.Screenshots.CaptureAsync(new ScreenshotRequest
{
Url = "https://example.com",
Device = "iPad Pro 11"
});Async jobs
For long-running captures:
// Create async job
var job = await client.Screenshots.CaptureAsyncJobAsync(new ScreenshotRequest
{
Url = "https://example.com",
FullPage = true
});
Console.WriteLine($"Job ID: {job.JobId}");
// Poll for completion
var status = await client.Jobs.GetAsync(job.JobId);
if (status.Status == "completed")
{
var imageBytes = await client.Jobs.GetResultAsync(job.JobId);
File.WriteAllBytes("screenshot.png", imageBytes);
}Bulk capture
Process multiple URLs efficiently:
var bulkJob = await client.Bulk.CreateAsync(new BulkRequest
{
Urls = new[]
{
new BulkUrl { Url = "https://example1.com" },
new BulkUrl { Url = "https://example2.com" },
new BulkUrl { Url = "https://example3.com" }
},
Defaults = new BulkDefaults
{
Device = "Desktop HD",
Format = "png"
}
});
// Check status
var status = await client.Bulk.GetAsync(bulkJob.BulkJobId);Composition
Combine multiple screenshots into a single image:
var composed = await client.Screenshots.ComposeAsync(new ComposeRequest
{
Url = "https://example.com",
Variants = new[]
{
new Variant { Device = "Desktop HD", Label = "Desktop" },
new Variant { Device = "iPhone 15", Label = "Mobile" }
},
Output = new OutputOptions
{
Layout = "horizontal",
Spacing = 20
}
});Schedules
Create recurring screenshot captures:
// Create a schedule
var schedule = await client.Schedules.CreateAsync(new CreateScheduleRequest
{
Name = "Daily Homepage",
Url = "https://example.com",
Schedule = "0 9 * * *",
Timezone = "America/New_York"
});
// List schedules
var schedules = await client.Schedules.ListAsync();
// Get captures
var captures = await client.Schedules.GetCapturesAsync(schedule.ScheduleId);Usage tracking
Monitor your API usage:
var usage = await client.Usage.GetAsync();
Console.WriteLine($"Screenshots: {usage.ScreenshotCount}/{usage.Quota}");ASP.NET Core integration
// Program.cs
builder.Services.AddAllScreenshots(options =>
{
options.ApiKey = builder.Configuration["AllScreenshots:ApiKey"];
});
// In your controller
public class ScreenshotController : ControllerBase
{
private readonly IAllScreenshotsClient _client;
public ScreenshotController(IAllScreenshotsClient client)
{
_client = client;
}
[HttpPost]
public async Task<IActionResult> Capture([FromBody] CaptureRequest request)
{
var imageBytes = await _client.Screenshots.CaptureAsync(new ScreenshotRequest
{
Url = request.Url
});
return File(imageBytes, "image/png");
}
}Error handling
using AllScreenshots.Sdk.Exceptions;
try
{
var imageBytes = await client.Screenshots.CaptureAsync(request);
}
catch (RateLimitException ex)
{
Console.WriteLine($"Rate limited. Retry after {ex.RetryAfter}s");
}
catch (AuthenticationException)
{
Console.WriteLine("Invalid API key");
}
catch (ValidationException ex)
{
Console.WriteLine($"Validation error: {ex.Message}");
}
catch (AllScreenshotsException ex)
{
Console.WriteLine($"API error: {ex.Message}");
}Requirements
- .NET 8.0 or later
License
Apache License 2.0