Skip to content
shotsmith
Features Docs Guides Pricing Changelog Sign inStart free

Embed live website screenshots with a signed <img> URL

Show an always-fresh screenshot of any website in an <img> tag, with a signed URL that keeps your API key safe in public HTML.

5 min read

The simplest way to show a screenshot of a website on your own page is an <img> tag that points straight at the API. No backend route, no storage, and the browser loads it like any other image. The catch is your API key: anyone can read it from the page source. Signed URLs solve that.

How signing works

You build the query string on your server, compute an HMAC-SHA256 of it with your secret key, and append it as signature. shotsmith recomputes the signature and refuses the request if anything was changed. So the URL is safe to publish: someone can copy it, but they can’t change the target URL or the options to spend your quota on something else.

The secret key never leaves your server. Only the access key and the signature appear in the page.

1. Get both keys

Create a free account. The API keys page shows an access key (shot_…) and a secret key (shot_sk_…). For public pages, turn on Require signed requests for the key, so unsigned requests with it are refused, and set Allowed domains to the sites you’ll capture.

2. Sign the URL on your server

Pick your language. Each produces the same URL, which you put in the page:

import { Shotsmith } from '@shotsmith/sdk';

const shotsmith = new Shotsmith({
  accessKey: 'shot_…',
  secretKey: process.env.SHOTSMITH_SECRET,
});

const src = await shotsmith.generateTakeUrl({
  url: 'https://shotsmith.dev/sample',
  format: 'webp',
  image_width: '600',
  cache: 'true',
});
<?php

require 'vendor/autoload.php';

use Shotsmith\Client;

$shotsmith = new Client('shot_…', secretKey: getenv('SHOTSMITH_SECRET'));

$src = $shotsmith->generateTakeUrl([
    'url' => 'https://shotsmith.dev/sample',
    'format' => 'webp',
    'image_width' => '600',
    'cache' => 'true',
]);
import crypto from 'node:crypto';

const query = new URLSearchParams({
  access_key: 'shot_…',
  url: 'https://shotsmith.dev/sample',
  format: 'webp',
  image_width: '600',
  cache: 'true',
}).toString();
const signature = crypto.createHmac('sha256', process.env.SHOTSMITH_SECRET).update(query).digest('hex');

const src = `https://shotsmith.dev/v1/take?${query}&signature=${signature}`;
import hashlib, hmac, os
from urllib.parse import urlencode, quote

query = urlencode({
    "access_key": "shot_…",
    "url": "https://shotsmith.dev/sample",
    "format": "webp",
    "image_width": "600",
    "cache": "true"
}, quote_via=quote)
signature = hmac.new(os.environ["SHOTSMITH_SECRET"].encode(), query.encode(), hashlib.sha256).hexdigest()

src = f"https://shotsmith.dev/v1/take?{query}&signature={signature}"
<?php

$query = http_build_query([
    'access_key' => 'shot_…',
    'url' => 'https://shotsmith.dev/sample',
    'format' => 'webp',
    'image_width' => '600',
    'cache' => 'true',
], '', '&', PHP_QUERY_RFC3986);
$signature = hash_hmac('sha256', $query, getenv('SHOTSMITH_SECRET'));

$src = "https://shotsmith.dev/v1/take?{$query}&signature={$signature}";
package main

import (
	"crypto/hmac"
	"crypto/sha256"
	"encoding/hex"
	"fmt"
	"net/url"
	"os"
)

func main() {
	params := url.Values{}
	params.Set("access_key", "shot_…")
	params.Set("url", "https://shotsmith.dev/sample")
	params.Set("format", "webp")
	params.Set("image_width", "600")
	params.Set("cache", "true")
	query := params.Encode()

	mac := hmac.New(sha256.New, []byte(os.Getenv("SHOTSMITH_SECRET")))
	mac.Write([]byte(query))
	signature := hex.EncodeToString(mac.Sum(nil))

	fmt.Println("https://shotsmith.dev/v1/take?" + query + "&signature=" + signature)
}
require "openssl"
require "uri"

query = URI.encode_www_form({
  "access_key" => "shot_…",
  "url" => "https://shotsmith.dev/sample",
  "format" => "webp",
  "image_width" => "600",
  "cache" => "true"
})
signature = OpenSSL::HMAC.hexdigest("SHA256", ENV.fetch("SHOTSMITH_SECRET"), query)

src = "https://shotsmith.dev/v1/take?#{query}&signature=#{signature}"

3. Put it in the page

<img
  src="https://shotsmith.dev/v1/take?access_key=shot_%E2%80%A6&url=https%3A%2F%2Fshotsmith.dev%2Fsample&format=webp&image_width=600&cache=true&signature=b40c241ae4331cf002ca8df9a87be60150abbffbc5839736e033062e6c3a6164"
  alt="Screenshot of example.com"
  width="600" loading="lazy">

loading="lazy" means screenshots below the fold are only requested when someone scrolls to them, so they don’t use renders for nobody.

Keep it fast and cheap

  • Turn on cache. Repeat requests for the same URL and options are served instantly from cache, and cache hits are free. cache_ttl sets how long, from 4 hours (the default) up to 30 days.
  • Ask for the size you show. image_width=600 returns a 600px-wide image instead of a full 1280px screenshot. Use device_scale_factor=2 if you need it sharp on high-density screens.
  • Choose WebP or AVIF for much smaller files than PNG.
  • Want one fresh capture a day? Add cache_key set to today’s date: each day gets its own cache entry.

Common mistakes

  • Signing a different string than you send. Sign the exact query string that ends up in the URL, encoded the same way and in the same order, without the signature parameter. The examples above do this.
  • Signing in the browser. That puts your secret key in the page, which defeats the point. Always sign on the server.

The authentication docs cover signing POST requests and the other key controls.