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.

    cURL screenshot examples 

  • 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.

    PHP screenshot examples 

  • 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.

    Node.js screenshot examples 

  • Python

    Python 3.10 or newer

    requests for scripts and httpx in a FastAPI route: the request, retries, a JSON body and signed URLs.

    Python screenshot examples 

  • Ruby

    Ruby 3.2 or newer

    Net::HTTP from the standard library: the request, retries, a JSON body, a Rails controller and signed URLs.

    Ruby screenshot examples 

  • 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.

    Java screenshot examples 

  • 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.

    C# screenshot examples 

  • 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.

    Go screenshot examples 

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:

Request
  • /v1/screenshot

    One address on api.urlshot.io, always. GET carries the options in the query; POST sends the same options as a JSON body.

  • ?url=https%3A%2F%2Fexample.com&format=webp

    The options, as query parameters. Each has a default, so only url is 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.

When it works
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.

When it does not
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.