Screenshot API code examples.
Every example here makes the same HTTP request: your key in a header, the page's address in the query, and the image in the response. There is no SDK to install, in any language.
Each page starts with a program you can run as it is, then covers what real code needs around it: errors and retries, a JSON body, a route in a web app, and a signed URL to put in a page.
cURL
curl and a POSIX shell
One command from any terminal, then a script that checks the status, retries when told to and signs URLs with openssl.
PHP
PHP 8.1 or newer, with cURL
The cURL extension and no Composer: the request, retries that honour Retry-After, a JSON body, a Laravel route and signed URLs.
Node.js
Node.js 18 or newer
fetch and writeFile, no SDK: the request, retries that honour Retry-After, a JSON body, an Express route and signed URLs.
Python
Python 3.10 or newer
requests for scripts and httpx in a FastAPI route: the request, retries, a JSON body and signed URLs.
Ruby
Ruby 3.2 or newer
Net::HTTP from the standard library: the request, retries, a JSON body, a Rails controller and signed URLs.
Java
Java 17 or newer
java.net.http and no dependencies: single-file programs, retries, a JSON body, a Spring Boot controller and signed URLs.
C# / .NET
.NET 8 or newer
HttpClient and System.Text.Json, no NuGet packages: the request, retries, a JSON body, a minimal API route and signed URLs.
Go
Go 1.22 or newer
net/http and encoding/json only: the request, retries, a JSON body, a handler that streams the image, and signed URLs.
The request every example makes.
What differs between the languages is only how each one sends an HTTP request and writes a file. The request itself is the same everywhere, and it has three parts to get right:
/v1/screenshotOne address on
api.urlshot.io, always.GETcarries the options in the query;POSTsends the same options as a JSON body.?url=https%3A%2F%2Fexample.com&format=webpThe options, as query parameters. Each has a default, so only
urlis required; the parameter reference lists all 17.Authorization: Bearer sk_…Your secret key, sent from your server and never from a browser. For an image in a page, sign the URL instead: see signed URLs.
What comes back
One of two answers, and the status code says which before you read a byte of the body.
200 OK
Content-Type: image/webp
X-Urlshot-Credits-Used: 1
X-Request-ID: req_…
(the screenshot, as WebP bytes)The body is the image itself, in the format you asked for. The headers say what the request cost and how to refer to it.
401 Unauthorized
Content-Type: application/json
{
"error": {
"code": "invalid_api_key",
"message": "The provided API key is not valid.",
"requestId": "req_…"
}
}Every failure is this JSON: a code to act on and the requestId to quote. When waiting will help, a Retry-After header says how long. All codes are in the error reference.
Every parameter, header and error code is in the API reference. To call the API through a generated client instead, point a generator at the OpenAPI document: the same contract the gateway checks every request against.
Make your first request.
100 screenshots a month on the free plan. No card needed.