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

Authentication and signing

Each key has a public access key and a private secret key. Send the access key with every request as access_key or the X-Access-Key header.

Signed requests

Signing proves a URL came from you and hasn’t been edited, so it’s safe to publish in HTML. To sign, take the query string exactly as you’ll send it (without signature), compute HMAC-SHA256 with your secret key, and append it as signature.

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: 'png',
});
<?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' => 'png',
]);
import crypto from 'node:crypto';

const query = new URLSearchParams({
  access_key: 'shot_…',
  url: 'https://shotsmith.dev/sample',
  format: 'png',
}).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": "png"
}, 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' => 'png',
], '', '&', 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", "png")
	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" => "png"
})
signature = OpenSSL::HMAC.hexdigest("SHA256", ENV.fetch("SHOTSMITH_SECRET"), query)

src = "https://shotsmith.dev/v1/take?#{query}&signature=#{signature}"
Output 200 OK
https://shotsmith.dev/v1/take?access_key=shot_%E2%80%A6&url=https%3A%2F%2Fshotsmith.dev%2Fsample&format=png&signature=c8bb758fc7418362f147d452763b3e54f3bf4a0dac018f7cdd54fdec24d6291d

Requesting that URL returns the image, exactly like an unsigned /v1/take call. Changing any parameter invalidates the signature and returns 403 with error_code: signature_is_not_valid.

For POST requests, sign the raw request body and send the result in the X-Signature header.

Key controls

  • Require signatures: unsigned requests with this key are refused.
  • Allowed domains: the key may only capture these hosts and their subdomains.
  • Allowed IPs: only these addresses or CIDR ranges may call with the key.
  • Monthly limit: the key stops after this many renders, independent of the account quota.

Rotate a secret from the API keys page; the access key stays the same so you only redeploy the signer.