Docs menu
API v3

Signed links

A screenshot as an image address, for an <img> tag: rendered on its first view, served from the cache after.

GEThttps://api.pagepeeker.com/v3/shot?options&key_id=key id&signature=signature

How it works

The link holds the options in its query, then key_id, the first 8 characters of your API key, and last signature: the HMAC-SHA256, in hex, of everything before &signature=, exactly as it is in the link, with your signing secret. Make it on your server: the secret never goes in a page. The key itself isn't in the link either.

import hashlib, hmac
from urllib.parse import urlencode

KEY_ID = "pp_xxxxx"  # the first 8 characters of your API key
SECRET = "YOUR_SIGNING_SECRET"

def signed_link(options):
    query = urlencode(options) + "&key_id=" + KEY_ID
    signature = hmac.new(SECRET.encode(), query.encode(), hashlib.sha256).hexdigest()
    return "https://api.pagepeeker.com/v3/shot?" + query + "&signature=" + signature

print(signed_link({"url": "https://example.com/", "width": 480, "height": 360}))

Any change to the link, an option or a character of its encoding, needs a new signature: the API checks the query exactly as it receives it. Booleans are true, false, 1 or 0 (lower case: Python's True is refused). wait is not taken.

What the browser gets

AnswerWhen
302 to the imageThe render is in the cache, or was done in up to 30 seconds. The redirect may be cached for what is left of cache_ttl.
A "being rendered" image, 640 x 480The render wasn't done in 30 seconds. Not cached: the next view gets the render.
A "not available" image, 640 x 480, with X-PP-Error-CodeThe page could not be rendered (the header has the reason), or the link was refused: invalid_signature, a wrong option, the rate limit, the quota.

What a view costs

  • Requests: every view of the link is a request, and counts toward your requests per minute like any other call. A view the browser answers from its own cache never reaches us and counts nothing.
  • Renders: a view costs a render only when the page is rendered: the first view, and the first one after cache_ttl has run out. Every other view is answered from the cache, for no render.
  • A wrong signature costs nothing: someone making up links can't use your requests or your renders.

A link with cache_ttl=2592000 (30 days, the most) costs at most one render every 30 days, however often it is viewed. A shorter cache_ttl gives a fresher image, for more renders.