Website screenshots & PDFs in Ruby

Leave Grover, wicked_pdf and a bundled Chromium out of your Rails deploy. Net::HTTP is all you need.

1. Get an API key

Click Get free key. You get 25 free renders a month instantly, no account needed. Store the key in an environment variable called SHOTMINT_KEY.

2. Screenshot a URL

require "net/http"
require "uri"

uri = URI("https://shotmint.creasework.com/v1/screenshot")
uri.query = URI.encode_www_form(url: "https://example.com", full_page: true)
req = Net::HTTP::Get.new(uri, "X-API-Key" => ENV.fetch("SHOTMINT_KEY"))
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true, read_timeout: 60) { |h| h.request(req) }
raise "Render failed: #{res.body}" unless res.is_a?(Net::HTTPSuccess)
File.binwrite("shot.png", res.body)

Useful parameters: full_page=true for the whole scrollable page, width/height for the viewport, device_scale_factor=2 for retina, selector to capture a single element, dark_mode=true, and hide_selectors to remove cookie banners. See the full list.

3. Turn HTML into a PDF

uri = URI("https://shotmint.creasework.com/v1/pdf")
req = Net::HTTP::Post.new(uri, "X-API-Key" => ENV.fetch("SHOTMINT_KEY"), "Content-Type" => "application/json")
req.body = { html: ApplicationController.render(template: "invoices/show", assigns: { invoice: @invoice }), format: "A4" }.to_json
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |h| h.request(req) }
send_data res.body, type: "application/pdf", filename: "invoice.pdf"

PDF options include format (A4, Letter…), landscape, margin, and print_background. You can pass a url instead of html.

Errors & credits

A failed render never costs a credit. Status 400 means bad input or an unreachable URL, 402 means you're out of credits, and 429/503 mean you should retry with backoff. Every successful response includes an X-Credits-Remaining header, and screenshots and PDFs of a URL also carry X-Page-Status: the HTTP status the site answered with. A 403 there usually means you captured the site's bot-protection page, a 404 its error page.

Production version: retries, timeouts and page status

The quickstart above stops at the first error. In production you want three more things: retry only the failures that can fix themselves (503 when the renderer is busy, network timeouts), never retry a 400 or 402, and warn when the site itself answered with an error page. This script does all three for screenshots and PDFs, and prints the credits left after each call:

require "net/http"
require "json"

API = URI("https://shotmint.creasework.com")

# Retries only what is worth retrying: 503 (renderer busy) and network timeouts.
# A 400 (bad input, unreachable site) or 402 (no credits) will not fix itself.
def render(path, params, attempts: 3)
  uri = API + path
  req = Net::HTTP::Post.new(uri, "X-API-Key" => ENV.fetch("SHOTMINT_KEY"), "Content-Type" => "application/json")
  req.body = params.to_json
  attempts.times do |i|
    begin
      res = Net::HTTP.start(uri.host, uri.port, use_ssl: true, open_timeout: 10, read_timeout: 90) { |h| h.request(req) }
    rescue Net::OpenTimeout, Net::ReadTimeout, Errno::ECONNRESET => e
      raise if i == attempts - 1
      sleep 2**i
      next
    end
    case res.code.to_i
    when 200
      page = res["X-Page-Status"].to_i
      warn "site answered #{page}: you may have captured an error or bot page" if page >= 400
      warn "credits left: #{res["X-Credits-Remaining"]}"
      return res.body
    when 503
      sleep 2**i
    else
      raise "#{res.code}: #{JSON.parse(res.body)["error"] rescue res.body}"
    end
  end
  raise "renderer still busy after #{attempts} attempts"
end

File.binwrite("shot.png", render("/v1/screenshot", { url: "https://en.wikipedia.org/wiki/Ruby_(programming_language)", full_page: true, format: "png" }))
File.binwrite("page.pdf", render("/v1/pdf", { url: "https://example.com", format: "A4" }))

Pass the parameters as an explicit hash, render(path, { url: ... }). Without the braces, Ruby 3 reads url: as keyword arguments and the call fails with ArgumentError: wrong number of arguments (given 1, expected 2), which is what our own first draft of this script did. Net::HTTP gives up after 60 s by default; the script raises that to 90 s.

Timing, measured on 2026-10-25: a full-page capture of a long Wikipedia article plus an A4 PDF took 8.5 to 25 s end to end, so keep the read timeout well above 30 s. Full-page captures are capped at 16,000 px tall (the Go and PHP articles hit that cap). With a format the API doesn't support, the script stops at once with the API's own message: 400: format must be png, jpeg or webp (got "gif").

Try it with 25 free renders a month

No signup, no card. Get a key in one click, then buy credits only if you need more (from €5 for 2,000, never expire). From a script, an AI agent, Make or Zapier, POST /v1/keys/free (no body) returns a key as JSON (openapi.json, no-code recipes).

Get a free API key Full API reference

More guides: API quickstarts by language

All guides: guides · integrations · comparisons