Documentation de l’API
Intégrez les captures PNG/JPEG, cartes Open Graph et PDF de ShotForge avec des exemples cURL, PHP et Python. Ce guide couvre l’authentification, les champs, les quotas et les erreurs, puis distingue les opérations réservées à une session navigateur.
Démarrage rapide
Créez un compte, générez une clé API, puis lancez votre premier rendu binaire en HTTPS.
- 1. Créez un compte ou connectez-vous.
- 2. Créez une clé dans Tableau de bord → Clés API. Copiez-la immédiatement.
- 3. Envoyez la clé dans X-API-Key et enregistrez la réponse binaire.
Première requête
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/octet-stream', 'Content-Type': 'application/json', 'X-API-Key': header_value(required('SHOTFORGE_API_KEY', None))}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/v1/screenshot')
(workdir / 'body').write_text(json.dumps({'url': required('SHOTFORGE_TARGET_URL', 'https://example.com')}))
PY
endpoint=$(<"$workdir/endpoint")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request POST \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--data-binary "@$workdir/body" \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" shotforge-screenshot.png "$workdir/response_headers" <<'PY'
import json, os, sys
from pathlib import Path
source, target = Path(sys.argv[1]), Path(sys.argv[2])
types = [line.split(':', 1)[1].strip().split(';')[0] for line in Path(sys.argv[3]).read_text().splitlines() if line.lower().startswith('content-type:')]
media_type = types[-1] if types else ''
if media_type not in ('image/png',):
raise SystemExit('Unexpected response media type')
with target.open('xb') as output:
output.write(source.read_bytes())
target.chmod(0o600)
print(f'Saved private response to {target}')
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/v1/screenshot';
$headers = ['Accept: application/octet-stream', 'Content-Type: application/json', 'X-API-Key: ' . headerValue(required('SHOTFORGE_API_KEY', null))];
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_POSTFIELDS => json_encode(['url' => required('SHOTFORGE_TARGET_URL', 'https://example.com')], JSON_THROW_ON_ERROR),
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
if (!in_array($mediaType, ['image/png'], true)) {
throw new RuntimeException('Unexpected response media type');
}
$target = 'shotforge-screenshot.png';
$output = fopen($target, 'xb');
if ($output === false) { throw new RuntimeException('Output already exists or cannot be created'); }
if (fwrite($output, $content) !== strlen($content)) {
fclose($output); throw new RuntimeException('Incomplete output');
}
fclose($output);
chmod($target, 0600);
echo "Saved private response to " . $target . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/v1/screenshot'
headers = {'Accept': 'application/octet-stream', 'Content-Type': 'application/json', 'X-API-Key': header_value(required('SHOTFORGE_API_KEY', None))}
payload = {'url': required('SHOTFORGE_TARGET_URL', 'https://example.com')}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False) as client:
response = client.request('POST', base_url + path, headers=headers, json=payload)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
if response.headers.get('content-type', '').split(';')[0] not in ('image/png',):
raise SystemExit('Unexpected response media type')
target = Path('shotforge-screenshot.png')
with target.open('xb') as output:
output.write(response.content)
target.chmod(0o600)
print(f'Saved private response to {target}')
En cas de succès, les endpoints de rendu renvoient des octets binaires et non du JSON : image/png, image/jpeg ou application/pdf. Enregistrez la réponse dans un fichier, puis vérifiez le statut HTTP et le type Content-Type avant de l’utiliser. Un fichier portant l’extension .png peut contenir une erreur JSON. Les exemples cURL utilisent Bash et Python 3 pour préparer des fichiers temporaires privés contenant les en-têtes et le corps de la requête. Les secrets ne sont pas placés dans les arguments du processus.
Chargez les clés, tokens et mots de passe dans les variables SHOTFORGE_* depuis votre gestionnaire de secrets. Les exemples cURL nécessitent Bash, curl et Python 3 ; PHP nécessite l’extension cURL ; pour Python, installez httpx avec pip install httpx. Les délais sont de 10 secondes pour la connexion et 90 secondes pour la requête. Gardez les fichiers de cookies et réponses sensibles privés ; n’affichez jamais leur contenu dans les logs. Les fichiers de sortie ne sont pas écrasés : déplacez ou supprimez le précédent avant de relancer le même exemple.
Authentification
Tous les endpoints de rendu exigent une clé API ou un token d’accès. Les clés API sont recommandées pour les intégrations serveur à serveur.
X-API-Key · Recommandé
X-API-Key: sk_EXAMPLE_NOT_A_REAL_KEYIdentifiant serveur longue durée. ShotForge ne stocke qu’une empreinte protégée par clé, jamais la clé brute.
Bearer JWT
Authorization: Bearer ACCESS_TOKENToken d’accès courte durée renvoyé par inscription, connexion ou renouvellement.
- Envoyez les identifiants uniquement dans les headers, jamais dans l’URL ou la query string.
- Une clé API n’est affichée qu’une fois à sa création. Stockez-la dans un gestionnaire de secrets ou une variable d’environnement.
- Chaque compte peut posséder jusqu’à 10 clés API actives.
- Révoquez et remplacez immédiatement toute clé potentiellement exposée.
Parcours d’authentification par tokens
L’inscription et la connexion API renvoient access_token et refresh_token, enregistrés ici dans un fichier privé. Chargez-les dans SHOTFORGE_ACCESS_TOKEN et SHOTFORGE_REFRESH_TOKEN pour les étapes suivantes. Le renouvellement remplace les deux valeurs : conservez la nouvelle paire et retirez l’ancien refresh token. Ces requêtes ne créent pas de session navigateur et n’autorisent pas la gestion du compte ou des clés.
POST /api/auth/register
Crée un compte. email ; mot de passe de 10 à 128 caractères avec une lettre et un chiffre ; full_name facultatif. Renvoie access_token et refresh_token.
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/auth/register')
(workdir / 'body').write_text(json.dumps({'email': required('SHOTFORGE_ACCOUNT_EMAIL', None), 'password': required('SHOTFORGE_ACCOUNT_PASSWORD', None), 'full_name': required('SHOTFORGE_FULL_NAME', '')}))
PY
endpoint=$(<"$workdir/endpoint")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request POST \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--data-binary "@$workdir/body" \
"$endpoint")
case "$http_status" in 201) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" shotforge-register-tokens.json "$workdir/response_headers" <<'PY'
import json, os, sys
from pathlib import Path
source, target = Path(sys.argv[1]), Path(sys.argv[2])
json.loads(source.read_text())
with target.open('xb') as output:
output.write(source.read_bytes())
target.chmod(0o600)
print(f'Saved private response to {target}')
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/auth/register';
$headers = ['Accept: application/json', 'Content-Type: application/json'];
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_POSTFIELDS => json_encode(['email' => required('SHOTFORGE_ACCOUNT_EMAIL', null), 'password' => required('SHOTFORGE_ACCOUNT_PASSWORD', null), 'full_name' => required('SHOTFORGE_FULL_NAME', '')], JSON_THROW_ON_ERROR),
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [201], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
json_decode($content, true, 512, JSON_THROW_ON_ERROR);
$target = 'shotforge-register-tokens.json';
$output = fopen($target, 'xb');
if ($output === false) { throw new RuntimeException('Output already exists or cannot be created'); }
if (fwrite($output, $content) !== strlen($content)) {
fclose($output); throw new RuntimeException('Incomplete output');
}
fclose($output);
chmod($target, 0600);
echo "Saved private response to " . $target . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/auth/register'
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
payload = {'email': required('SHOTFORGE_ACCOUNT_EMAIL', None), 'password': required('SHOTFORGE_ACCOUNT_PASSWORD', None), 'full_name': required('SHOTFORGE_FULL_NAME', '')}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False) as client:
response = client.request('POST', base_url + path, headers=headers, json=payload)
if response.status_code not in (201,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
response.json()
target = Path('shotforge-register-tokens.json')
with target.open('xb') as output:
output.write(response.content)
target.chmod(0o600)
print(f'Saved private response to {target}')
POST /api/auth/login
Authentifie par email et mot de passe. Renvoie une nouvelle paire accès/renouvellement.
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/auth/login')
(workdir / 'body').write_text(json.dumps({'email': required('SHOTFORGE_ACCOUNT_EMAIL', None), 'password': required('SHOTFORGE_ACCOUNT_PASSWORD', None)}))
PY
endpoint=$(<"$workdir/endpoint")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request POST \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--data-binary "@$workdir/body" \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" shotforge-login-tokens.json "$workdir/response_headers" <<'PY'
import json, os, sys
from pathlib import Path
source, target = Path(sys.argv[1]), Path(sys.argv[2])
json.loads(source.read_text())
with target.open('xb') as output:
output.write(source.read_bytes())
target.chmod(0o600)
print(f'Saved private response to {target}')
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/auth/login';
$headers = ['Accept: application/json', 'Content-Type: application/json'];
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_POSTFIELDS => json_encode(['email' => required('SHOTFORGE_ACCOUNT_EMAIL', null), 'password' => required('SHOTFORGE_ACCOUNT_PASSWORD', null)], JSON_THROW_ON_ERROR),
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
json_decode($content, true, 512, JSON_THROW_ON_ERROR);
$target = 'shotforge-login-tokens.json';
$output = fopen($target, 'xb');
if ($output === false) { throw new RuntimeException('Output already exists or cannot be created'); }
if (fwrite($output, $content) !== strlen($content)) {
fclose($output); throw new RuntimeException('Incomplete output');
}
fclose($output);
chmod($target, 0600);
echo "Saved private response to " . $target . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/auth/login'
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
payload = {'email': required('SHOTFORGE_ACCOUNT_EMAIL', None), 'password': required('SHOTFORGE_ACCOUNT_PASSWORD', None)}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False) as client:
response = client.request('POST', base_url + path, headers=headers, json=payload)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
response.json()
target = Path('shotforge-login-tokens.json')
with target.open('xb') as output:
output.write(response.content)
target.chmod(0o600)
print(f'Saved private response to {target}')
POST /api/auth/refresh
Renouvelle un refresh token. Le token envoyé devient inutilisable ; sa réutilisation révoque tous les refresh tokens du compte. Les access tokens existants expirent naturellement sous 30 minutes.
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/auth/refresh')
(workdir / 'body').write_text(json.dumps({'refresh_token': required('SHOTFORGE_REFRESH_TOKEN', None)}))
PY
endpoint=$(<"$workdir/endpoint")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request POST \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--data-binary "@$workdir/body" \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" shotforge-refreshed-tokens.json "$workdir/response_headers" <<'PY'
import json, os, sys
from pathlib import Path
source, target = Path(sys.argv[1]), Path(sys.argv[2])
json.loads(source.read_text())
with target.open('xb') as output:
output.write(source.read_bytes())
target.chmod(0o600)
print(f'Saved private response to {target}')
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/auth/refresh';
$headers = ['Accept: application/json', 'Content-Type: application/json'];
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_POSTFIELDS => json_encode(['refresh_token' => required('SHOTFORGE_REFRESH_TOKEN', null)], JSON_THROW_ON_ERROR),
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
json_decode($content, true, 512, JSON_THROW_ON_ERROR);
$target = 'shotforge-refreshed-tokens.json';
$output = fopen($target, 'xb');
if ($output === false) { throw new RuntimeException('Output already exists or cannot be created'); }
if (fwrite($output, $content) !== strlen($content)) {
fclose($output); throw new RuntimeException('Incomplete output');
}
fclose($output);
chmod($target, 0600);
echo "Saved private response to " . $target . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/auth/refresh'
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
payload = {'refresh_token': required('SHOTFORGE_REFRESH_TOKEN', None)}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False) as client:
response = client.request('POST', base_url + path, headers=headers, json=payload)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
response.json()
target = Path('shotforge-refreshed-tokens.json')
with target.open('xb') as output:
output.write(response.content)
target.chmod(0o600)
print(f'Saved private response to {target}')
POST /api/auth/logout
Révoque le refresh_token fourni dans le corps JSON. Renvoie 204.
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/auth/logout')
(workdir / 'body').write_text(json.dumps({'refresh_token': required('SHOTFORGE_REFRESH_TOKEN', None)}))
PY
endpoint=$(<"$workdir/endpoint")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request POST \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--data-binary "@$workdir/body" \
"$endpoint")
case "$http_status" in 204) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
printf 'HTTP %s\n' "$http_status"
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/auth/logout';
$headers = ['Accept: application/json', 'Content-Type: application/json'];
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_POSTFIELDS => json_encode(['refresh_token' => required('SHOTFORGE_REFRESH_TOKEN', null)], JSON_THROW_ON_ERROR),
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [204], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
echo "HTTP " . $status . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/auth/logout'
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
payload = {'refresh_token': required('SHOTFORGE_REFRESH_TOKEN', None)}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False) as client:
response = client.request('POST', base_url + path, headers=headers, json=payload)
if response.status_code not in (204,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
print(f'HTTP {response.status_code}')
GET /api/auth/usage · Bearer
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/json', 'Authorization': header_value('Bearer ' + required('SHOTFORGE_ACCESS_TOKEN', None))}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/auth/usage')
PY
endpoint=$(<"$workdir/endpoint")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request GET \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" <<'PY'
import json, sys
from pathlib import Path
print(json.dumps(json.loads(Path(sys.argv[1]).read_text()), indent=2))
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/auth/usage';
$headers = ['Accept: application/json', 'Authorization: ' . headerValue('Bearer ' . required('SHOTFORGE_ACCESS_TOKEN', null))];
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
echo json_encode(json_decode($content, true, 512, JSON_THROW_ON_ERROR), JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR) . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/auth/usage'
headers = {'Accept': 'application/json', 'Authorization': header_value('Bearer ' + required('SHOTFORGE_ACCESS_TOKEN', None))}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False) as client:
response = client.request('GET', base_url + path, headers=headers)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
print(json.dumps(response.json(), indent=2))
Forfaits, quotas et limites de débit
L’essai de 14 jours bénéficie des capacités Pro. Les limites du forfait sont vérifiées avant de lancer Chromium.
| Forfait | Rendus / mois | Largeur maximale | Page complète | Pages authentifiées | Historique | |
|---|---|---|---|---|---|---|
| Free | 100 | 1280 px | — | — | — | 7 jours |
| Starter | 5000 | 1920 px | ✓ | ✓ | — | 30 jours |
| Pro / Essai | 50000 | 2560 px | ✓ | ✓ | ✓ | 30 jours |
| Business | 500000 | 3840 px | ✓ | ✓ | ✓ | 90 jours |
30 requêtes de rendu par minute et par clé API, ou par IP avec un token Bearer. Une réponse 429 contient Retry-After: 60.
Seuls les rendus réussis consomment le quota mensuel. Les réservations en cours empêchent les requêtes concurrentes de dépasser la limite. Le quota repart à zéro le premier du mois à 00:00 UTC.
GET /api/auth/usage
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/json', 'X-API-Key': header_value(required('SHOTFORGE_API_KEY', None))}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/auth/usage')
PY
endpoint=$(<"$workdir/endpoint")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request GET \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" <<'PY'
import json, sys
from pathlib import Path
print(json.dumps(json.loads(Path(sys.argv[1]).read_text()), indent=2))
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/auth/usage';
$headers = ['Accept: application/json', 'X-API-Key: ' . headerValue(required('SHOTFORGE_API_KEY', null))];
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
echo json_encode(json_decode($content, true, 512, JSON_THROW_ON_ERROR), JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR) . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/auth/usage'
headers = {'Accept': 'application/json', 'X-API-Key': header_value(required('SHOTFORGE_API_KEY', None))}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False) as client:
response = client.request('GET', base_url + path, headers=headers)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
print(json.dumps(response.json(), indent=2))
Sondes et catalogue public des forfaits
Ces routes GET sont publiques et ne consomment aucun crédit de rendu.
GET /health
Vérifie que le processus répond. Un statut 200 ne prouve pas que la base ou le stockage sont prêts.
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/json'}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/health')
PY
endpoint=$(<"$workdir/endpoint")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request GET \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" <<'PY'
import json, sys
from pathlib import Path
print(json.dumps(json.loads(Path(sys.argv[1]).read_text()), indent=2))
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/health';
$headers = ['Accept: application/json'];
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
echo json_encode(json_decode($content, true, 512, JSON_THROW_ON_ERROR), JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR) . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/health'
headers = {'Accept': 'application/json'}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False) as client:
response = client.request('GET', base_url + path, headers=headers)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
print(json.dumps(response.json(), indent=2))
GET /ready
Vérifie la connexion à la base et la version des migrations. En production, valide aussi la configuration locale du stockage, sans tester le bucket distant. Renvoie 503 si ces prérequis ne sont pas satisfaits.
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/json'}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/ready')
PY
endpoint=$(<"$workdir/endpoint")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request GET \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" <<'PY'
import json, sys
from pathlib import Path
print(json.dumps(json.loads(Path(sys.argv[1]).read_text()), indent=2))
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/ready';
$headers = ['Accept: application/json'];
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
echo json_encode(json_decode($content, true, 512, JSON_THROW_ON_ERROR), JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR) . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/ready'
headers = {'Accept': 'application/json'}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False) as client:
response = client.request('GET', base_url + path, headers=headers)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
print(json.dumps(response.json(), indent=2))
GET /api/billing/plans
Renvoie les forfaits et leurs quotas, limites de fonctionnalités et durées de conservation de l’historique.
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/json'}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/billing/plans')
PY
endpoint=$(<"$workdir/endpoint")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request GET \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" <<'PY'
import json, sys
from pathlib import Path
print(json.dumps(json.loads(Path(sys.argv[1]).read_text()), indent=2))
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/billing/plans';
$headers = ['Accept: application/json'];
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
echo json_encode(json_decode($content, true, 512, JSON_THROW_ON_ERROR), JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR) . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/billing/plans'
headers = {'Accept': 'application/json'}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False) as client:
response = client.request('GET', base_url + path, headers=headers)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
print(json.dumps(response.json(), indent=2))
Endpoints de démonstration anonymes
Les démonstrations publiques du site acceptent des formulaires sans compte. Ce sont des outils d’évaluation, pas l’API de production versionnée ; utilisez les endpoints /api/v1 authentifiés pour une intégration.
| Endpoint | Content-Type | Champs | Réponse |
|---|---|---|---|
| POST /tools/screenshot | application/x-www-form-urlencoded | url, width (200–1920), height (200–2000) | image/png |
| POST /tools/og | application/x-www-form-urlencoded | url, template, title, subtitle, brand | image/png · 1200×630 |
L’outil OG anonyme accepte uniquement les trois identifiants ci-dessous. Free et Starter connectés donnent accès à 41 modèles ; Pro, Business et l’essai Pro actif aux 72. Le mode raw reste disponible indépendamment.
ember-frame · ocean-split · paper-editorial
POST /tools/screenshot
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/octet-stream', 'Content-Type': 'application/x-www-form-urlencoded'}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/tools/screenshot')
(workdir / 'body').write_text(urlencode({'url': required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'width': 1280, 'height': 720}))
PY
endpoint=$(<"$workdir/endpoint")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request POST \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--data-binary "@$workdir/body" \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" shotforge-anonymous.png "$workdir/response_headers" <<'PY'
import json, os, sys
from pathlib import Path
source, target = Path(sys.argv[1]), Path(sys.argv[2])
types = [line.split(':', 1)[1].strip().split(';')[0] for line in Path(sys.argv[3]).read_text().splitlines() if line.lower().startswith('content-type:')]
media_type = types[-1] if types else ''
if media_type not in ('image/png',):
raise SystemExit('Unexpected response media type')
with target.open('xb') as output:
output.write(source.read_bytes())
target.chmod(0o600)
print(f'Saved private response to {target}')
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/tools/screenshot';
$headers = ['Accept: application/octet-stream', 'Content-Type: application/x-www-form-urlencoded'];
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_POSTFIELDS => http_build_query(['url' => required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'width' => 1280, 'height' => 720]),
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
if (!in_array($mediaType, ['image/png'], true)) {
throw new RuntimeException('Unexpected response media type');
}
$target = 'shotforge-anonymous.png';
$output = fopen($target, 'xb');
if ($output === false) { throw new RuntimeException('Output already exists or cannot be created'); }
if (fwrite($output, $content) !== strlen($content)) {
fclose($output); throw new RuntimeException('Incomplete output');
}
fclose($output);
chmod($target, 0600);
echo "Saved private response to " . $target . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/tools/screenshot'
headers = {'Accept': 'application/octet-stream', 'Content-Type': 'application/x-www-form-urlencoded'}
payload = {'url': required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'width': 1280, 'height': 720}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False) as client:
response = client.request('POST', base_url + path, headers=headers, data=payload)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
if response.headers.get('content-type', '').split(';')[0] not in ('image/png',):
raise SystemExit('Unexpected response media type')
target = Path('shotforge-anonymous.png')
with target.open('xb') as output:
output.write(response.content)
target.chmod(0o600)
print(f'Saved private response to {target}')
POST /tools/og
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/octet-stream', 'Content-Type': 'application/x-www-form-urlencoded'}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/tools/og')
(workdir / 'body').write_text(urlencode({'url': required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'template': 'ember-frame', 'title': 'Your next idea', 'subtitle': 'A fresh view', 'brand': 'Your app'}))
PY
endpoint=$(<"$workdir/endpoint")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request POST \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--data-binary "@$workdir/body" \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" shotforge-anonymous-og.png "$workdir/response_headers" <<'PY'
import json, os, sys
from pathlib import Path
source, target = Path(sys.argv[1]), Path(sys.argv[2])
types = [line.split(':', 1)[1].strip().split(';')[0] for line in Path(sys.argv[3]).read_text().splitlines() if line.lower().startswith('content-type:')]
media_type = types[-1] if types else ''
if media_type not in ('image/png',):
raise SystemExit('Unexpected response media type')
with target.open('xb') as output:
output.write(source.read_bytes())
target.chmod(0o600)
print(f'Saved private response to {target}')
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/tools/og';
$headers = ['Accept: application/octet-stream', 'Content-Type: application/x-www-form-urlencoded'];
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_POSTFIELDS => http_build_query(['url' => required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'template' => 'ember-frame', 'title' => 'Your next idea', 'subtitle' => 'A fresh view', 'brand' => 'Your app']),
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
if (!in_array($mediaType, ['image/png'], true)) {
throw new RuntimeException('Unexpected response media type');
}
$target = 'shotforge-anonymous-og.png';
$output = fopen($target, 'xb');
if ($output === false) { throw new RuntimeException('Output already exists or cannot be created'); }
if (fwrite($output, $content) !== strlen($content)) {
fclose($output); throw new RuntimeException('Incomplete output');
}
fclose($output);
chmod($target, 0600);
echo "Saved private response to " . $target . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/tools/og'
headers = {'Accept': 'application/octet-stream', 'Content-Type': 'application/x-www-form-urlencoded'}
payload = {'url': required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'template': 'ember-frame', 'title': 'Your next idea', 'subtitle': 'A fresh view', 'brand': 'Your app'}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False) as client:
response = client.request('POST', base_url + path, headers=headers, data=payload)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
if response.headers.get('content-type', '').split(';')[0] not in ('image/png',):
raise SystemExit('Unexpected response media type')
target = Path('shotforge-anonymous-og.png')
with target.open('xb') as output:
output.write(response.content)
target.chmod(0o600)
print(f'Saved private response to {target}')
Les outils anonymes sont limités à 10 requêtes par minute et par IP, sans consommer le quota d’un compte. Ils ne prennent pas en charge JPEG, la page complète, l’authentification de la cible, le PDF ni les dimensions supérieures aux limites indiquées.
/api/v1/screenshot
Rend une page web en PNG ou JPEG, avec zone d’affichage fixe ou capture avec défilement.
| Champ | Type | Défaut | Description |
|---|---|---|---|
| url | string | — | URL absolue http:// ou https:// obligatoire. Les destinations privées, loopback, link-local, réservées et les redirections vers celles-ci sont bloquées. |
| width | integer | 1280 | 200–3840 px, avec le plafond supplémentaire du forfait actif. |
| height | integer | 800 | 200–5000 px. Ignoré comme hauteur finale quand full_page vaut true. |
| full_page | boolean | false | Starter et supérieur. Fait défiler le contenu chargé à la demande et capture la page avec une hauteur automatique. |
| format | string | png | png | jpeg |
| delay_ms | integer | 0 | Attente supplémentaire après navigation : 0–10000 ms. |
| clean | boolean | true | Ferme les bandeaux cookies, consentements RGPD et widgets de chat courants avant la capture. |
| auth | object | null | null | Identifiants facultatifs et à usage unique pour le site cible ; Starter et supérieur. |
Capture en JPEG
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/octet-stream', 'Content-Type': 'application/json', 'X-API-Key': header_value(required('SHOTFORGE_API_KEY', None))}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/v1/screenshot')
(workdir / 'body').write_text(json.dumps({'url': required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'width': 1280, 'height': 800, 'format': 'jpeg', 'clean': True}))
PY
endpoint=$(<"$workdir/endpoint")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request POST \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--data-binary "@$workdir/body" \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" shotforge-screenshot.jpeg "$workdir/response_headers" <<'PY'
import json, os, sys
from pathlib import Path
source, target = Path(sys.argv[1]), Path(sys.argv[2])
types = [line.split(':', 1)[1].strip().split(';')[0] for line in Path(sys.argv[3]).read_text().splitlines() if line.lower().startswith('content-type:')]
media_type = types[-1] if types else ''
if media_type not in ('image/jpeg',):
raise SystemExit('Unexpected response media type')
with target.open('xb') as output:
output.write(source.read_bytes())
target.chmod(0o600)
print(f'Saved private response to {target}')
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/v1/screenshot';
$headers = ['Accept: application/octet-stream', 'Content-Type: application/json', 'X-API-Key: ' . headerValue(required('SHOTFORGE_API_KEY', null))];
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_POSTFIELDS => json_encode(['url' => required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'width' => 1280, 'height' => 800, 'format' => 'jpeg', 'clean' => true], JSON_THROW_ON_ERROR),
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
if (!in_array($mediaType, ['image/jpeg'], true)) {
throw new RuntimeException('Unexpected response media type');
}
$target = 'shotforge-screenshot.jpeg';
$output = fopen($target, 'xb');
if ($output === false) { throw new RuntimeException('Output already exists or cannot be created'); }
if (fwrite($output, $content) !== strlen($content)) {
fclose($output); throw new RuntimeException('Incomplete output');
}
fclose($output);
chmod($target, 0600);
echo "Saved private response to " . $target . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/v1/screenshot'
headers = {'Accept': 'application/octet-stream', 'Content-Type': 'application/json', 'X-API-Key': header_value(required('SHOTFORGE_API_KEY', None))}
payload = {'url': required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'width': 1280, 'height': 800, 'format': 'jpeg', 'clean': True}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False) as client:
response = client.request('POST', base_url + path, headers=headers, json=payload)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
if response.headers.get('content-type', '').split(';')[0] not in ('image/jpeg',):
raise SystemExit('Unexpected response media type')
target = Path('shotforge-screenshot.jpeg')
with target.open('xb') as output:
output.write(response.content)
target.chmod(0o600)
print(f'Saved private response to {target}')
Exemple de capture pleine page
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/octet-stream', 'Content-Type': 'application/json', 'X-API-Key': header_value(required('SHOTFORGE_API_KEY', None))}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/v1/screenshot')
(workdir / 'body').write_text(json.dumps({'url': required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'width': 1280, 'height': 800, 'full_page': True, 'delay_ms': 1000, 'clean': True}))
PY
endpoint=$(<"$workdir/endpoint")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request POST \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--data-binary "@$workdir/body" \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" shotforge-fullpage.png "$workdir/response_headers" <<'PY'
import json, os, sys
from pathlib import Path
source, target = Path(sys.argv[1]), Path(sys.argv[2])
types = [line.split(':', 1)[1].strip().split(';')[0] for line in Path(sys.argv[3]).read_text().splitlines() if line.lower().startswith('content-type:')]
media_type = types[-1] if types else ''
if media_type not in ('image/png',):
raise SystemExit('Unexpected response media type')
with target.open('xb') as output:
output.write(source.read_bytes())
target.chmod(0o600)
print(f'Saved private response to {target}')
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/v1/screenshot';
$headers = ['Accept: application/octet-stream', 'Content-Type: application/json', 'X-API-Key: ' . headerValue(required('SHOTFORGE_API_KEY', null))];
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_POSTFIELDS => json_encode(['url' => required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'width' => 1280, 'height' => 800, 'full_page' => true, 'delay_ms' => 1000, 'clean' => true], JSON_THROW_ON_ERROR),
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
if (!in_array($mediaType, ['image/png'], true)) {
throw new RuntimeException('Unexpected response media type');
}
$target = 'shotforge-fullpage.png';
$output = fopen($target, 'xb');
if ($output === false) { throw new RuntimeException('Output already exists or cannot be created'); }
if (fwrite($output, $content) !== strlen($content)) {
fclose($output); throw new RuntimeException('Incomplete output');
}
fclose($output);
chmod($target, 0600);
echo "Saved private response to " . $target . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/v1/screenshot'
headers = {'Accept': 'application/octet-stream', 'Content-Type': 'application/json', 'X-API-Key': header_value(required('SHOTFORGE_API_KEY', None))}
payload = {'url': required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'width': 1280, 'height': 800, 'full_page': True, 'delay_ms': 1000, 'clean': True}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False) as client:
response = client.request('POST', base_url + path, headers=headers, json=payload)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
if response.headers.get('content-type', '').split(';')[0] not in ('image/png',):
raise SystemExit('Unexpected response media type')
target = Path('shotforge-fullpage.png')
with target.open('xb') as output:
output.write(response.content)
target.chmod(0o600)
print(f'Saved private response to {target}')
🔒 Pages cibles authentifiées
Capturez une page protégée par HTTP Basic ou un formulaire de connexion en ajoutant auth à la requête de capture. Disponible avec Starter, Pro, Business et l’essai Pro.
| Champ | Type | Défaut | Description |
|---|---|---|---|
| auth.username | string | — | Identifiant ou email du site cible, de 1 à 200 caractères. |
| auth.password | string | — | Mot de passe du site cible, de 1 à 200 caractères. À envoyer uniquement en HTTPS. |
| auth.type | string | basic | basic pour HTTP Basic sur la même origine ; form pour remplir et soumettre un formulaire de connexion. |
| auth.selectors | object | null | auto | Sélecteurs CSS facultatifs nommés username, password et submit. Des sélecteurs automatiques sont utilisés s’ils sont absents. |
Authentification HTTP Basic du site cible
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/octet-stream', 'Content-Type': 'application/json', 'X-API-Key': header_value(required('SHOTFORGE_API_KEY', None))}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/v1/screenshot')
(workdir / 'body').write_text(json.dumps({'url': required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'auth': {'username': required('SHOTFORGE_TARGET_USERNAME', None), 'password': required('SHOTFORGE_TARGET_PASSWORD', None), 'type': 'basic'}}))
PY
endpoint=$(<"$workdir/endpoint")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request POST \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--data-binary "@$workdir/body" \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" shotforge-basic.png "$workdir/response_headers" <<'PY'
import json, os, sys
from pathlib import Path
source, target = Path(sys.argv[1]), Path(sys.argv[2])
types = [line.split(':', 1)[1].strip().split(';')[0] for line in Path(sys.argv[3]).read_text().splitlines() if line.lower().startswith('content-type:')]
media_type = types[-1] if types else ''
if media_type not in ('image/png',):
raise SystemExit('Unexpected response media type')
with target.open('xb') as output:
output.write(source.read_bytes())
target.chmod(0o600)
print(f'Saved private response to {target}')
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/v1/screenshot';
$headers = ['Accept: application/octet-stream', 'Content-Type: application/json', 'X-API-Key: ' . headerValue(required('SHOTFORGE_API_KEY', null))];
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_POSTFIELDS => json_encode(['url' => required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'auth' => ['username' => required('SHOTFORGE_TARGET_USERNAME', null), 'password' => required('SHOTFORGE_TARGET_PASSWORD', null), 'type' => 'basic']], JSON_THROW_ON_ERROR),
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
if (!in_array($mediaType, ['image/png'], true)) {
throw new RuntimeException('Unexpected response media type');
}
$target = 'shotforge-basic.png';
$output = fopen($target, 'xb');
if ($output === false) { throw new RuntimeException('Output already exists or cannot be created'); }
if (fwrite($output, $content) !== strlen($content)) {
fclose($output); throw new RuntimeException('Incomplete output');
}
fclose($output);
chmod($target, 0600);
echo "Saved private response to " . $target . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/v1/screenshot'
headers = {'Accept': 'application/octet-stream', 'Content-Type': 'application/json', 'X-API-Key': header_value(required('SHOTFORGE_API_KEY', None))}
payload = {'url': required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'auth': {'username': required('SHOTFORGE_TARGET_USERNAME', None), 'password': required('SHOTFORGE_TARGET_PASSWORD', None), 'type': 'basic'}}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False) as client:
response = client.request('POST', base_url + path, headers=headers, json=payload)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
if response.headers.get('content-type', '').split(';')[0] not in ('image/png',):
raise SystemExit('Unexpected response media type')
target = Path('shotforge-basic.png')
with target.open('xb') as output:
output.write(response.content)
target.chmod(0o600)
print(f'Saved private response to {target}')
Formulaire de connexion du site cible
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/octet-stream', 'Content-Type': 'application/json', 'X-API-Key': header_value(required('SHOTFORGE_API_KEY', None))}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/v1/screenshot')
(workdir / 'body').write_text(json.dumps({'url': required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'auth': {'username': required('SHOTFORGE_TARGET_USERNAME', None), 'password': required('SHOTFORGE_TARGET_PASSWORD', None), 'type': 'form', 'selectors': {'username': 'input[name=email]', 'password': 'input[name=password]', 'submit': 'button[type=submit]'}}}))
PY
endpoint=$(<"$workdir/endpoint")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request POST \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--data-binary "@$workdir/body" \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" shotforge-form.png "$workdir/response_headers" <<'PY'
import json, os, sys
from pathlib import Path
source, target = Path(sys.argv[1]), Path(sys.argv[2])
types = [line.split(':', 1)[1].strip().split(';')[0] for line in Path(sys.argv[3]).read_text().splitlines() if line.lower().startswith('content-type:')]
media_type = types[-1] if types else ''
if media_type not in ('image/png',):
raise SystemExit('Unexpected response media type')
with target.open('xb') as output:
output.write(source.read_bytes())
target.chmod(0o600)
print(f'Saved private response to {target}')
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/v1/screenshot';
$headers = ['Accept: application/octet-stream', 'Content-Type: application/json', 'X-API-Key: ' . headerValue(required('SHOTFORGE_API_KEY', null))];
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_POSTFIELDS => json_encode(['url' => required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'auth' => ['username' => required('SHOTFORGE_TARGET_USERNAME', null), 'password' => required('SHOTFORGE_TARGET_PASSWORD', null), 'type' => 'form', 'selectors' => ['username' => 'input[name=email]', 'password' => 'input[name=password]', 'submit' => 'button[type=submit]']]], JSON_THROW_ON_ERROR),
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
if (!in_array($mediaType, ['image/png'], true)) {
throw new RuntimeException('Unexpected response media type');
}
$target = 'shotforge-form.png';
$output = fopen($target, 'xb');
if ($output === false) { throw new RuntimeException('Output already exists or cannot be created'); }
if (fwrite($output, $content) !== strlen($content)) {
fclose($output); throw new RuntimeException('Incomplete output');
}
fclose($output);
chmod($target, 0600);
echo "Saved private response to " . $target . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/v1/screenshot'
headers = {'Accept': 'application/octet-stream', 'Content-Type': 'application/json', 'X-API-Key': header_value(required('SHOTFORGE_API_KEY', None))}
payload = {'url': required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'auth': {'username': required('SHOTFORGE_TARGET_USERNAME', None), 'password': required('SHOTFORGE_TARGET_PASSWORD', None), 'type': 'form', 'selectors': {'username': 'input[name=email]', 'password': 'input[name=password]', 'submit': 'button[type=submit]'}}}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False) as client:
response = client.request('POST', base_url + path, headers=headers, json=payload)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
if response.headers.get('content-type', '').split(';')[0] not in ('image/png',):
raise SystemExit('Unexpected response media type')
target = Path('shotforge-form.png')
with target.open('xb') as output:
output.write(response.content)
target.chmod(0o600)
print(f'Saved private response to {target}')
Les identifiants cibles sont utilisés uniquement dans le contexte navigateur isolé de cette requête. Ils ne sont jamais stockés, journalisés, renvoyés ni inclus dans l’historique d’utilisation.
/api/v1/og-templates
Endpoint public de découverte. lang accepte en ou fr et renvoie les 72 identifiants, noms localisés, métadonnées visuelles et required_plan (free ou pro). Le rendu vérifie l’offre effective avant la réservation du quota.
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/json'}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/v1/og-templates?lang=fr')
PY
endpoint=$(<"$workdir/endpoint")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request GET \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" <<'PY'
import json, sys
from pathlib import Path
print(json.dumps(json.loads(Path(sys.argv[1]).read_text()), indent=2))
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/v1/og-templates?lang=fr';
$headers = ['Accept: application/json'];
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
echo json_encode(json_decode($content, true, 512, JSON_THROW_ON_ERROR), JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR) . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/v1/og-templates?lang=fr'
headers = {'Accept': 'application/json'}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False) as client:
response = client.request('GET', base_url + path, headers=headers)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
print(json.dumps(response.json(), indent=2))
/api/v1/og-image
Renvoie image/png. raw conserve le contrat historique de capture de zone d’affichage ; chaque modèle nommé compose une vraie capture de la page cible dans une carte fixe 1200×630.
| Champ | Type | Défaut | Description |
|---|---|---|---|
| url | string | — | URL absolue http:// ou https:// obligatoire. Les destinations privées, loopback, link-local, réservées et les redirections vers celles-ci sont bloquées. |
| template | string | raw | raw ou un identifiant renvoyé par GET /api/v1/og-templates. |
| width | integer | 1200 | Mode raw uniquement : 200–1200 px. Les modèles composés font toujours 1200 px. |
| height | integer | 630 | Mode raw uniquement : 200–630 px. Les modèles composés font toujours 630 px. |
| title | string | "" | Titre facultatif du modèle composé, 120 caractères maximum. |
| subtitle | string | "" | Sous-titre facultatif, 220 caractères maximum. |
| brand | string | "" | Libellé de marque facultatif, 60 caractères maximum. |
Capture OG sans modèle : mode raw
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/octet-stream', 'Content-Type': 'application/json', 'X-API-Key': header_value(required('SHOTFORGE_API_KEY', None))}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/v1/og-image')
(workdir / 'body').write_text(json.dumps({'url': required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'template': 'raw', 'width': 1200, 'height': 630}))
PY
endpoint=$(<"$workdir/endpoint")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request POST \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--data-binary "@$workdir/body" \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" shotforge-og-raw.png "$workdir/response_headers" <<'PY'
import json, os, sys
from pathlib import Path
source, target = Path(sys.argv[1]), Path(sys.argv[2])
types = [line.split(':', 1)[1].strip().split(';')[0] for line in Path(sys.argv[3]).read_text().splitlines() if line.lower().startswith('content-type:')]
media_type = types[-1] if types else ''
if media_type not in ('image/png',):
raise SystemExit('Unexpected response media type')
with target.open('xb') as output:
output.write(source.read_bytes())
target.chmod(0o600)
print(f'Saved private response to {target}')
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/v1/og-image';
$headers = ['Accept: application/octet-stream', 'Content-Type: application/json', 'X-API-Key: ' . headerValue(required('SHOTFORGE_API_KEY', null))];
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_POSTFIELDS => json_encode(['url' => required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'template' => 'raw', 'width' => 1200, 'height' => 630], JSON_THROW_ON_ERROR),
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
if (!in_array($mediaType, ['image/png'], true)) {
throw new RuntimeException('Unexpected response media type');
}
$target = 'shotforge-og-raw.png';
$output = fopen($target, 'xb');
if ($output === false) { throw new RuntimeException('Output already exists or cannot be created'); }
if (fwrite($output, $content) !== strlen($content)) {
fclose($output); throw new RuntimeException('Incomplete output');
}
fclose($output);
chmod($target, 0600);
echo "Saved private response to " . $target . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/v1/og-image'
headers = {'Accept': 'application/octet-stream', 'Content-Type': 'application/json', 'X-API-Key': header_value(required('SHOTFORGE_API_KEY', None))}
payload = {'url': required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'template': 'raw', 'width': 1200, 'height': 630}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False) as client:
response = client.request('POST', base_url + path, headers=headers, json=payload)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
if response.headers.get('content-type', '').split(';')[0] not in ('image/png',):
raise SystemExit('Unexpected response media type')
target = Path('shotforge-og-raw.png')
with target.open('xb') as output:
output.write(response.content)
target.chmod(0o600)
print(f'Saved private response to {target}')
Renvoie image/png. raw conserve le contrat historique de capture de zone d’affichage ; chaque modèle nommé compose une vraie capture de la page cible dans une carte fixe 1200×630.
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/octet-stream', 'Content-Type': 'application/json', 'X-API-Key': header_value(required('SHOTFORGE_API_KEY', None))}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/v1/og-image')
(workdir / 'body').write_text(json.dumps({'url': required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'template': 'ember-frame', 'title': 'Your next idea', 'subtitle': 'A fresh view of your work', 'brand': 'Your app'}))
PY
endpoint=$(<"$workdir/endpoint")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request POST \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--data-binary "@$workdir/body" \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" shotforge-og-template.png "$workdir/response_headers" <<'PY'
import json, os, sys
from pathlib import Path
source, target = Path(sys.argv[1]), Path(sys.argv[2])
types = [line.split(':', 1)[1].strip().split(';')[0] for line in Path(sys.argv[3]).read_text().splitlines() if line.lower().startswith('content-type:')]
media_type = types[-1] if types else ''
if media_type not in ('image/png',):
raise SystemExit('Unexpected response media type')
with target.open('xb') as output:
output.write(source.read_bytes())
target.chmod(0o600)
print(f'Saved private response to {target}')
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/v1/og-image';
$headers = ['Accept: application/octet-stream', 'Content-Type: application/json', 'X-API-Key: ' . headerValue(required('SHOTFORGE_API_KEY', null))];
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_POSTFIELDS => json_encode(['url' => required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'template' => 'ember-frame', 'title' => 'Your next idea', 'subtitle' => 'A fresh view of your work', 'brand' => 'Your app'], JSON_THROW_ON_ERROR),
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
if (!in_array($mediaType, ['image/png'], true)) {
throw new RuntimeException('Unexpected response media type');
}
$target = 'shotforge-og-template.png';
$output = fopen($target, 'xb');
if ($output === false) { throw new RuntimeException('Output already exists or cannot be created'); }
if (fwrite($output, $content) !== strlen($content)) {
fclose($output); throw new RuntimeException('Incomplete output');
}
fclose($output);
chmod($target, 0600);
echo "Saved private response to " . $target . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/v1/og-image'
headers = {'Accept': 'application/octet-stream', 'Content-Type': 'application/json', 'X-API-Key': header_value(required('SHOTFORGE_API_KEY', None))}
payload = {'url': required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'template': 'ember-frame', 'title': 'Your next idea', 'subtitle': 'A fresh view of your work', 'brand': 'Your app'}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False) as client:
response = client.request('POST', base_url + path, headers=headers, json=payload)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
if response.headers.get('content-type', '').split(';')[0] not in ('image/png',):
raise SystemExit('Unexpected response media type')
target = Path('shotforge-og-template.png')
with target.open('xb') as output:
output.write(response.content)
target.chmod(0o600)
print(f'Saved private response to {target}')
Identifiants de modèles disponibles (72)
ember-framemidnight-browserpaper-editorialviolet-orbitlime-terminalocean-splitcoral-stackmono-brutalaurora-glasssunset-cardroyal-deviceblueprintrose-magazinesand-galleryneon-circuitforest-windowruby-postersilver-minimalgold-luxeindigo-focusmint-polaroidcharcoal-newspeach-friendlycyber-gridlavender-floatred-alertsky-dashboardcopper-angleplum-storyice-cleanobsidian-commandcream-serifemerald-sidebarcobalt-cascadetangerine-labelgraphite-gridlinefuchsia-collagealpine-cardnoir-cinemalemon-popteal-ticketbrick-reportpearl-productultraviolet-scanmoss-notebookcobalt-phonecrimson-covercyan-isometricclay-windowacid-zinenavy-statblush-lettertungsten-panelamber-quotejade-maplilac-appscarlet-ribbonarctic-doccoffee-stampspectrum-prismsonic-pulsevault-balanceatlas-ticketspectrum-mosaicjournal-spreadhorizon-deckporcelain-typeink-spotlightcitrus-cutoutcerulean-foldterracotta-indexchrome-stage/api/v1/pdf
Rend une page web en application/pdf. Disponible avec Pro, Business et l’essai Pro.
| Champ | Type | Défaut | Description |
|---|---|---|---|
| url | string | — | URL absolue http:// ou https:// obligatoire. Les destinations privées, loopback, link-local, réservées et les redirections vers celles-ci sont bloquées. |
| format | string | A4 | A4 | A3 | Letter | Legal |
| landscape | boolean | false | Utilise l’orientation paysage. |
| print_background | boolean | true | Inclut les arrière-plans CSS dans le PDF. |
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/octet-stream', 'Content-Type': 'application/json', 'X-API-Key': header_value(required('SHOTFORGE_API_KEY', None))}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/v1/pdf')
(workdir / 'body').write_text(json.dumps({'url': required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'format': 'A4', 'landscape': False, 'print_background': True}))
PY
endpoint=$(<"$workdir/endpoint")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request POST \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--data-binary "@$workdir/body" \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" shotforge.pdf "$workdir/response_headers" <<'PY'
import json, os, sys
from pathlib import Path
source, target = Path(sys.argv[1]), Path(sys.argv[2])
types = [line.split(':', 1)[1].strip().split(';')[0] for line in Path(sys.argv[3]).read_text().splitlines() if line.lower().startswith('content-type:')]
media_type = types[-1] if types else ''
if media_type not in ('application/pdf',):
raise SystemExit('Unexpected response media type')
with target.open('xb') as output:
output.write(source.read_bytes())
target.chmod(0o600)
print(f'Saved private response to {target}')
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/v1/pdf';
$headers = ['Accept: application/octet-stream', 'Content-Type: application/json', 'X-API-Key: ' . headerValue(required('SHOTFORGE_API_KEY', null))];
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_POSTFIELDS => json_encode(['url' => required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'format' => 'A4', 'landscape' => false, 'print_background' => true], JSON_THROW_ON_ERROR),
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
if (!in_array($mediaType, ['application/pdf'], true)) {
throw new RuntimeException('Unexpected response media type');
}
$target = 'shotforge.pdf';
$output = fopen($target, 'xb');
if ($output === false) { throw new RuntimeException('Output already exists or cannot be created'); }
if (fwrite($output, $content) !== strlen($content)) {
fclose($output); throw new RuntimeException('Incomplete output');
}
fclose($output);
chmod($target, 0600);
echo "Saved private response to " . $target . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/v1/pdf'
headers = {'Accept': 'application/octet-stream', 'Content-Type': 'application/json', 'X-API-Key': header_value(required('SHOTFORGE_API_KEY', None))}
payload = {'url': required('SHOTFORGE_TARGET_URL', 'https://example.com'), 'format': 'A4', 'landscape': False, 'print_background': True}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False) as client:
response = client.request('POST', base_url + path, headers=headers, json=payload)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
if response.headers.get('content-type', '').split(';')[0] not in ('application/pdf',):
raise SystemExit('Unexpected response media type')
target = Path('shotforge.pdf')
with target.open('xb') as output:
output.write(response.content)
target.chmod(0o600)
print(f'Saved private response to {target}')
Historique de l’espace connecté
GET /api/v1/history?page=1 retourne 30 résultats maximum, triés du plus récent au plus ancien. La réponse indique items, page, page_size, total, total_pages et retention_days. page commence à 1. GET /api/v1/history/{id}/download renvoie les octets conservés sans régénération ni crédit supplémentaire.
L’historique et ses téléchargements exigent le cookie shotforge_token d’une session navigateur. Les clés API et tokens Bearer sont refusés, même si un cookie valide accompagne la requête. Établissez d’abord la session avec POST /app/login dans le parcours de gestion du compte ci-dessous.
Conservation : Free 7 jours, Starter 30 jours, Pro 30 jours, Business 90 jours. Un essai Pro actif utilise la durée Pro. Il n’y a pas de plafond de 30 fichiers : 30 est la taille d’une page. Les fichiers expirés renvoient 404, même si leur suppression du bucket est encore en attente.
GET /api/v1/history?page=1
{
"items": [{
"id": "0123456789abcdef0123456789abcdef",
"kind": "screenshot", "media_type": "image/png",
"filename": "screenshot.png", "byte_size": 48230,
"created_at": "2026-09-29T12:00:00Z",
"download_url": "/api/v1/history/0123456789abcdef0123456789abcdef/download"
}],
"page": 1, "page_size": 30, "total": 1,
"total_pages": 1, "retention_days": 30
}
Un changement d’offre modifie immédiatement la fenêtre accessible. Les fichiers déjà supprimés ne sont pas restaurés. Projets et sources ont une conservation indépendante. GET /api/billing/plans expose history_retention_days pour chaque offre. Les générations anonymes ne sont pas ajoutées à un historique de compte.
GET /api/v1/history?page=1
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/json'}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/v1/history?page=1')
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
if not cookie_file.is_file():
raise SystemExit('Run session_login first')
(workdir / 'cookie_path').write_text(str(cookie_file))
PY
endpoint=$(<"$workdir/endpoint")
cookie_file=$(<"$workdir/cookie_path")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request GET \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--cookie "$cookie_file" \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" <<'PY'
import json, sys
from pathlib import Path
print(json.dumps(json.loads(Path(sys.argv[1]).read_text()), indent=2))
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/v1/history?page=1';
$headers = ['Accept: application/json'];
$cookieFile = required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt');
if (file_exists($cookieFile) && (fileperms($cookieFile) & 0077)) {
throw new RuntimeException('Cookie jar must have mode 600');
}
if (!is_file($cookieFile)) { throw new RuntimeException('Run session_login first'); }
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_COOKIEFILE => $cookieFile,
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
echo json_encode(json_decode($content, true, 512, JSON_THROW_ON_ERROR), JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR) . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/v1/history?page=1'
headers = {'Accept': 'application/json'}
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
cookies = http.cookiejar.MozillaCookieJar(str(cookie_file))
if not cookie_file.is_file():
raise SystemExit('Run session_login first')
cookies.load(ignore_discard=True, ignore_expires=False)
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False, cookies=cookies) as client:
response = client.request('GET', base_url + path, headers=headers)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
print(json.dumps(response.json(), indent=2))
GET /api/v1/history/{id}/download
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/octet-stream'}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/v1/history/{artifact_id}/download'.replace('{artifact_id}', quote(required('SHOTFORGE_ARTIFACT_ID', None), safe='')))
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
if not cookie_file.is_file():
raise SystemExit('Run session_login first')
(workdir / 'cookie_path').write_text(str(cookie_file))
PY
endpoint=$(<"$workdir/endpoint")
cookie_file=$(<"$workdir/cookie_path")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request GET \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--cookie "$cookie_file" \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" shotforge-artifact.bin "$workdir/response_headers" <<'PY'
import json, os, sys
from pathlib import Path
source, target = Path(sys.argv[1]), Path(sys.argv[2])
types = [line.split(':', 1)[1].strip().split(';')[0] for line in Path(sys.argv[3]).read_text().splitlines() if line.lower().startswith('content-type:')]
media_type = types[-1] if types else ''
if not media_type or media_type == 'application/json':
raise SystemExit('Unexpected response media type')
with target.open('xb') as output:
output.write(source.read_bytes())
target.chmod(0o600)
print(f'Saved private response to {target}')
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/v1/history/{artifact_id}/download';
$path = str_replace('{artifact_id}', rawurlencode(required('SHOTFORGE_ARTIFACT_ID', null)), $path);
$headers = ['Accept: application/octet-stream'];
$cookieFile = required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt');
if (file_exists($cookieFile) && (fileperms($cookieFile) & 0077)) {
throw new RuntimeException('Cookie jar must have mode 600');
}
if (!is_file($cookieFile)) { throw new RuntimeException('Run session_login first'); }
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_COOKIEFILE => $cookieFile,
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
if ($mediaType === '' || $mediaType === 'application/json') {
throw new RuntimeException('Unexpected response media type');
}
$target = 'shotforge-artifact.bin';
$output = fopen($target, 'xb');
if ($output === false) { throw new RuntimeException('Output already exists or cannot be created'); }
if (fwrite($output, $content) !== strlen($content)) {
fclose($output); throw new RuntimeException('Incomplete output');
}
fclose($output);
chmod($target, 0600);
echo "Saved private response to " . $target . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/v1/history/{artifact_id}/download'.replace('{artifact_id}', quote(required('SHOTFORGE_ARTIFACT_ID', None), safe=''))
headers = {'Accept': 'application/octet-stream'}
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
cookies = http.cookiejar.MozillaCookieJar(str(cookie_file))
if not cookie_file.is_file():
raise SystemExit('Run session_login first')
cookies.load(ignore_discard=True, ignore_expires=False)
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False, cookies=cookies) as client:
response = client.request('GET', base_url + path, headers=headers)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
if not response.headers.get('content-type') or response.headers.get('content-type', '').split(';')[0] == 'application/json':
raise SystemExit('Unexpected response media type')
target = Path('shotforge-artifact.bin')
with target.open('xb') as output:
output.write(response.content)
target.chmod(0o600)
print(f'Saved private response to {target}')
Endpoints de compte et de clés
Le tableau précise l’authentification de chaque route. L’inscription et les tokens sont décrits plus haut ; les opérations de gestion ci-dessous nécessitent une session navigateur, distincte des identifiants utilisés pour le rendu.
| Méthode | Endpoint | Authentification | Description |
|---|---|---|---|
| POST | /api/auth/register | — | Crée un compte. email ; mot de passe de 10 à 128 caractères avec une lettre et un chiffre ; full_name facultatif. Renvoie access_token et refresh_token. |
| POST | /api/auth/login | — | Authentifie par email et mot de passe. Renvoie une nouvelle paire accès/renouvellement. |
| POST | /api/auth/refresh | Refresh token | Renouvelle un refresh token. Le token envoyé devient inutilisable ; sa réutilisation révoque tous les refresh tokens du compte. Les access tokens existants expirent naturellement sous 30 minutes. |
| POST | /api/auth/logout | Refresh token | Révoque le refresh_token fourni dans le corps JSON. Renvoie 204. |
| GET | /api/auth/me | Session navigateur | Renvoie l’identité du compte, le forfait effectif et l’état de l’abonnement. |
| GET | /api/auth/usage | API key / Bearer / Session navigateur | Renvoie les rendus réussis utilisés pendant le mois UTC, la limite, le pourcentage et le forfait effectif. |
| GET | /api/auth/keys | Session navigateur | Liste uniquement les métadonnées des clés ; les clés brutes et empreintes ne sont jamais renvoyées. |
| POST | /api/auth/keys | Session navigateur | Crée une clé nommée (name : 1–100 caractères). La valeur api_key brute n’est renvoyée qu’une fois. |
| DELETE | /api/auth/keys/{id} | Session navigateur | Révoque une clé appartenant au compte authentifié et coupe immédiatement son accès au rendu. Basculez les intégrations concernées vers une autre clé avant de la révoquer. Renvoie 204. |
| GET | /api/auth/export | Session navigateur | Exporte en JSON le compte, les métadonnées de clés, l’historique d’utilisation nettoyé et les métadonnées de sessions. Les secrets et empreintes sont exclus. |
| POST | /api/auth/delete-account | Session navigateur | Supprime définitivement le compte après vérification du mot de passe. Corps : email et password. Renvoie 204. |
| GET | /api/billing/plans | — | Catalogue public en temps réel : prix, quotas, largeurs et fonctionnalités. |
| GET | /api/billing/status | Session navigateur | Renvoie le forfait de facturation enregistré, l’état de l’abonnement et la disponibilité de Stripe. |
| POST | /api/billing/checkout | Session navigateur | Crée une session de paiement intégré pour starter, pro ou business après validation fiscale. Renvoie session_id et client_secret ; ne journalisez pas la réponse. La requête seule ne confirme aucun paiement. |
| POST | /api/billing/portal | Session navigateur | Compatibilité locale : renvoie portal_url avec /app/billing pour ouvrir l’espace de facturation ShotForge. |
Les tokens d’accès expirent après 30 minutes. Les refresh tokens expirent après 7 jours et tournent à chaque renouvellement. Un changement ou une réinitialisation du mot de passe révoque les sessions actives. L’inscription et la connexion sont limitées à 20 tentatives par minute et par IP. Un compte est d’abord verrouillé 5 minutes après 5 échecs consécutifs ; les échecs suivants appliquent un délai exponentiel plafonné à 24 heures.
Gestion avec une session navigateur
POST /app/login crée le cookie de session conservé dans un fichier privé. Réutilisez ce fichier pour l’identité, les clés, l’export et la suppression du compte. Aucun en-tête X-API-Key ou Authorization ne doit accompagner ces opérations ; la connexion JSON /api/auth/login ne fournit pas le cookie requis.
POST /app/login
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/json', 'Content-Type': 'application/x-www-form-urlencoded'}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/app/login')
(workdir / 'body').write_text(urlencode({'email': required('SHOTFORGE_ACCOUNT_EMAIL', None), 'password': required('SHOTFORGE_ACCOUNT_PASSWORD', None), 'lang': 'fr'}))
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
cookie_file.touch(mode=0o600, exist_ok=True)
(workdir / 'cookie_path').write_text(str(cookie_file))
PY
endpoint=$(<"$workdir/endpoint")
cookie_file=$(<"$workdir/cookie_path")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request POST \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--cookie "$cookie_file" \
--cookie-jar "$cookie_file" \
--data-binary "@$workdir/body" \
"$endpoint")
case "$http_status" in 302|303) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$cookie_file" <<'PY'
import http.cookiejar, sys
cookies = http.cookiejar.MozillaCookieJar(sys.argv[1])
cookies.load(ignore_discard=True, ignore_expires=False)
if not any(cookie.name == 'shotforge_token' and cookie.value for cookie in cookies):
raise SystemExit('No browser session cookie received')
PY
printf 'Browser session cookie jar saved privately.\n'
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/app/login';
$headers = ['Accept: application/json', 'Content-Type: application/x-www-form-urlencoded'];
$cookieFile = required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt');
if (file_exists($cookieFile) && (fileperms($cookieFile) & 0077)) {
throw new RuntimeException('Cookie jar must have mode 600');
}
if (!file_exists($cookieFile) && !touch($cookieFile)) {
throw new RuntimeException('Cannot create cookie jar');
}
chmod($cookieFile, 0600);
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_COOKIEFILE => $cookieFile,
CURLOPT_COOKIEJAR => $cookieFile,
CURLOPT_POSTFIELDS => http_build_query(['email' => required('SHOTFORGE_ACCOUNT_EMAIL', null), 'password' => required('SHOTFORGE_ACCOUNT_PASSWORD', null), 'lang' => 'fr']),
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [302, 303], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
chmod($cookieFile, 0600);
if (!str_contains((string) file_get_contents($cookieFile), "\tshotforge_token\t")) {
throw new RuntimeException('No browser session cookie received');
}
echo "Browser session cookie jar saved privately.\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/app/login'
headers = {'Accept': 'application/json', 'Content-Type': 'application/x-www-form-urlencoded'}
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
cookies = http.cookiejar.MozillaCookieJar(str(cookie_file))
payload = {'email': required('SHOTFORGE_ACCOUNT_EMAIL', None), 'password': required('SHOTFORGE_ACCOUNT_PASSWORD', None), 'lang': 'fr'}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False, cookies=cookies) as client:
response = client.request('POST', base_url + path, headers=headers, data=payload)
if response.status_code not in (302, 303):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
if not any(cookie.name == 'shotforge_token' and cookie.value for cookie in client.cookies.jar):
raise SystemExit('No browser session cookie received')
cookies.save(ignore_discard=True, ignore_expires=False)
cookie_file.chmod(0o600)
print('Browser session cookie jar saved privately.')
GET /api/auth/keys
Liste uniquement les métadonnées des clés ; les clés brutes et empreintes ne sont jamais renvoyées.
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/json'}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/auth/keys')
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
if not cookie_file.is_file():
raise SystemExit('Run session_login first')
(workdir / 'cookie_path').write_text(str(cookie_file))
PY
endpoint=$(<"$workdir/endpoint")
cookie_file=$(<"$workdir/cookie_path")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request GET \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--cookie "$cookie_file" \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" <<'PY'
import json, sys
from pathlib import Path
print(json.dumps(json.loads(Path(sys.argv[1]).read_text()), indent=2))
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/auth/keys';
$headers = ['Accept: application/json'];
$cookieFile = required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt');
if (file_exists($cookieFile) && (fileperms($cookieFile) & 0077)) {
throw new RuntimeException('Cookie jar must have mode 600');
}
if (!is_file($cookieFile)) { throw new RuntimeException('Run session_login first'); }
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_COOKIEFILE => $cookieFile,
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
echo json_encode(json_decode($content, true, 512, JSON_THROW_ON_ERROR), JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR) . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/auth/keys'
headers = {'Accept': 'application/json'}
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
cookies = http.cookiejar.MozillaCookieJar(str(cookie_file))
if not cookie_file.is_file():
raise SystemExit('Run session_login first')
cookies.load(ignore_discard=True, ignore_expires=False)
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False, cookies=cookies) as client:
response = client.request('GET', base_url + path, headers=headers)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
print(json.dumps(response.json(), indent=2))
POST /api/auth/keys
Crée une clé nommée (name : 1–100 caractères). La valeur api_key brute n’est renvoyée qu’une fois.
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/auth/keys')
(workdir / 'body').write_text(json.dumps({'name': 'Documentation client'}))
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
if not cookie_file.is_file():
raise SystemExit('Run session_login first')
(workdir / 'cookie_path').write_text(str(cookie_file))
PY
endpoint=$(<"$workdir/endpoint")
cookie_file=$(<"$workdir/cookie_path")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request POST \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--cookie "$cookie_file" \
--data-binary "@$workdir/body" \
"$endpoint")
case "$http_status" in 201) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" shotforge-created-key.json "$workdir/response_headers" <<'PY'
import json, os, sys
from pathlib import Path
source, target = Path(sys.argv[1]), Path(sys.argv[2])
json.loads(source.read_text())
with target.open('xb') as output:
output.write(source.read_bytes())
target.chmod(0o600)
print(f'Saved private response to {target}')
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/auth/keys';
$headers = ['Accept: application/json', 'Content-Type: application/json'];
$cookieFile = required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt');
if (file_exists($cookieFile) && (fileperms($cookieFile) & 0077)) {
throw new RuntimeException('Cookie jar must have mode 600');
}
if (!is_file($cookieFile)) { throw new RuntimeException('Run session_login first'); }
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_COOKIEFILE => $cookieFile,
CURLOPT_POSTFIELDS => json_encode(['name' => 'Documentation client'], JSON_THROW_ON_ERROR),
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [201], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
json_decode($content, true, 512, JSON_THROW_ON_ERROR);
$target = 'shotforge-created-key.json';
$output = fopen($target, 'xb');
if ($output === false) { throw new RuntimeException('Output already exists or cannot be created'); }
if (fwrite($output, $content) !== strlen($content)) {
fclose($output); throw new RuntimeException('Incomplete output');
}
fclose($output);
chmod($target, 0600);
echo "Saved private response to " . $target . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/auth/keys'
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
cookies = http.cookiejar.MozillaCookieJar(str(cookie_file))
if not cookie_file.is_file():
raise SystemExit('Run session_login first')
cookies.load(ignore_discard=True, ignore_expires=False)
payload = {'name': 'Documentation client'}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False, cookies=cookies) as client:
response = client.request('POST', base_url + path, headers=headers, json=payload)
if response.status_code not in (201,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
response.json()
target = Path('shotforge-created-key.json')
with target.open('xb') as output:
output.write(response.content)
target.chmod(0o600)
print(f'Saved private response to {target}')
DELETE /api/auth/keys/{id}
Révoque une clé appartenant au compte authentifié et coupe immédiatement son accès au rendu. Basculez les intégrations concernées vers une autre clé avant de la révoquer. Renvoie 204.
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/json'}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/auth/keys/{key_id}'.replace('{key_id}', quote(required('SHOTFORGE_KEY_ID', None), safe='')))
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
if not cookie_file.is_file():
raise SystemExit('Run session_login first')
(workdir / 'cookie_path').write_text(str(cookie_file))
PY
endpoint=$(<"$workdir/endpoint")
cookie_file=$(<"$workdir/cookie_path")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request DELETE \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--cookie "$cookie_file" \
"$endpoint")
case "$http_status" in 204) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
printf 'HTTP %s\n' "$http_status"
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/auth/keys/{key_id}';
$path = str_replace('{key_id}', rawurlencode(required('SHOTFORGE_KEY_ID', null)), $path);
$headers = ['Accept: application/json'];
$cookieFile = required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt');
if (file_exists($cookieFile) && (fileperms($cookieFile) & 0077)) {
throw new RuntimeException('Cookie jar must have mode 600');
}
if (!is_file($cookieFile)) { throw new RuntimeException('Run session_login first'); }
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'DELETE',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_COOKIEFILE => $cookieFile,
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [204], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
echo "HTTP " . $status . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/auth/keys/{key_id}'.replace('{key_id}', quote(required('SHOTFORGE_KEY_ID', None), safe=''))
headers = {'Accept': 'application/json'}
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
cookies = http.cookiejar.MozillaCookieJar(str(cookie_file))
if not cookie_file.is_file():
raise SystemExit('Run session_login first')
cookies.load(ignore_discard=True, ignore_expires=False)
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False, cookies=cookies) as client:
response = client.request('DELETE', base_url + path, headers=headers)
if response.status_code not in (204,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
print(f'HTTP {response.status_code}')
GET /api/auth/me
Renvoie l’identité du compte, le forfait effectif et l’état de l’abonnement.
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/json'}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/auth/me')
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
if not cookie_file.is_file():
raise SystemExit('Run session_login first')
(workdir / 'cookie_path').write_text(str(cookie_file))
PY
endpoint=$(<"$workdir/endpoint")
cookie_file=$(<"$workdir/cookie_path")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request GET \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--cookie "$cookie_file" \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" <<'PY'
import json, sys
from pathlib import Path
print(json.dumps(json.loads(Path(sys.argv[1]).read_text()), indent=2))
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/auth/me';
$headers = ['Accept: application/json'];
$cookieFile = required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt');
if (file_exists($cookieFile) && (fileperms($cookieFile) & 0077)) {
throw new RuntimeException('Cookie jar must have mode 600');
}
if (!is_file($cookieFile)) { throw new RuntimeException('Run session_login first'); }
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_COOKIEFILE => $cookieFile,
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
echo json_encode(json_decode($content, true, 512, JSON_THROW_ON_ERROR), JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR) . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/auth/me'
headers = {'Accept': 'application/json'}
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
cookies = http.cookiejar.MozillaCookieJar(str(cookie_file))
if not cookie_file.is_file():
raise SystemExit('Run session_login first')
cookies.load(ignore_discard=True, ignore_expires=False)
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False, cookies=cookies) as client:
response = client.request('GET', base_url + path, headers=headers)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
print(json.dumps(response.json(), indent=2))
GET /api/auth/export
Exporte en JSON le compte, les métadonnées de clés, l’historique d’utilisation nettoyé et les métadonnées de sessions. Les secrets et empreintes sont exclus.
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/json'}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/auth/export')
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
if not cookie_file.is_file():
raise SystemExit('Run session_login first')
(workdir / 'cookie_path').write_text(str(cookie_file))
PY
endpoint=$(<"$workdir/endpoint")
cookie_file=$(<"$workdir/cookie_path")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request GET \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--cookie "$cookie_file" \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" shotforge-account-export.json "$workdir/response_headers" <<'PY'
import json, os, sys
from pathlib import Path
source, target = Path(sys.argv[1]), Path(sys.argv[2])
json.loads(source.read_text())
with target.open('xb') as output:
output.write(source.read_bytes())
target.chmod(0o600)
print(f'Saved private response to {target}')
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/auth/export';
$headers = ['Accept: application/json'];
$cookieFile = required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt');
if (file_exists($cookieFile) && (fileperms($cookieFile) & 0077)) {
throw new RuntimeException('Cookie jar must have mode 600');
}
if (!is_file($cookieFile)) { throw new RuntimeException('Run session_login first'); }
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_COOKIEFILE => $cookieFile,
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
json_decode($content, true, 512, JSON_THROW_ON_ERROR);
$target = 'shotforge-account-export.json';
$output = fopen($target, 'xb');
if ($output === false) { throw new RuntimeException('Output already exists or cannot be created'); }
if (fwrite($output, $content) !== strlen($content)) {
fclose($output); throw new RuntimeException('Incomplete output');
}
fclose($output);
chmod($target, 0600);
echo "Saved private response to " . $target . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/auth/export'
headers = {'Accept': 'application/json'}
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
cookies = http.cookiejar.MozillaCookieJar(str(cookie_file))
if not cookie_file.is_file():
raise SystemExit('Run session_login first')
cookies.load(ignore_discard=True, ignore_expires=False)
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False, cookies=cookies) as client:
response = client.request('GET', base_url + path, headers=headers)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
response.json()
target = Path('shotforge-account-export.json')
with target.open('xb') as output:
output.write(response.content)
target.chmod(0o600)
print(f'Saved private response to {target}')
shotforge-created-key.json est privé et contient la clé api_key brute, renvoyée une seule fois. Transférez-la dans votre gestionnaire de secrets, puis supprimez le fichier privé. La liste des clés ne renvoie ensuite que les métadonnées et le préfixe non sensible.
POST /api/auth/delete-account
Cette requête supprime définitivement le compte et ses données après vérification du mot de passe et traitement de la facturation. Vérifiez le compte ciblé et exportez les données à conserver avant de l’exécuter. La suppression ne peut pas être annulée.
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/auth/delete-account')
(workdir / 'body').write_text(json.dumps({'email': required('SHOTFORGE_ACCOUNT_EMAIL', None), 'password': required('SHOTFORGE_ACCOUNT_PASSWORD', None)}))
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
if not cookie_file.is_file():
raise SystemExit('Run session_login first')
(workdir / 'cookie_path').write_text(str(cookie_file))
PY
endpoint=$(<"$workdir/endpoint")
cookie_file=$(<"$workdir/cookie_path")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request POST \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--cookie "$cookie_file" \
--data-binary "@$workdir/body" \
"$endpoint")
case "$http_status" in 204) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
printf 'HTTP %s\n' "$http_status"
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/auth/delete-account';
$headers = ['Accept: application/json', 'Content-Type: application/json'];
$cookieFile = required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt');
if (file_exists($cookieFile) && (fileperms($cookieFile) & 0077)) {
throw new RuntimeException('Cookie jar must have mode 600');
}
if (!is_file($cookieFile)) { throw new RuntimeException('Run session_login first'); }
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_COOKIEFILE => $cookieFile,
CURLOPT_POSTFIELDS => json_encode(['email' => required('SHOTFORGE_ACCOUNT_EMAIL', null), 'password' => required('SHOTFORGE_ACCOUNT_PASSWORD', null)], JSON_THROW_ON_ERROR),
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [204], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
echo "HTTP " . $status . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/auth/delete-account'
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
cookies = http.cookiejar.MozillaCookieJar(str(cookie_file))
if not cookie_file.is_file():
raise SystemExit('Run session_login first')
cookies.load(ignore_discard=True, ignore_expires=False)
payload = {'email': required('SHOTFORGE_ACCOUNT_EMAIL', None), 'password': required('SHOTFORGE_ACCOUNT_PASSWORD', None)}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False, cookies=cookies) as client:
response = client.request('POST', base_url + path, headers=headers, json=payload)
if response.status_code not in (204,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
print(f'HTTP {response.status_code}')
La facturation exige une session navigateur ; ses mutations exigent aussi l’Origin exact de ShotForge. Checkout nécessite un profil fiscal complet et renvoie session_id et client_secret pour le paiement intégré Stripe, sans URL de paiement hébergée. Gardez cette réponse privée et terminez le paiement dans l’interface de facturation. Le portail de compatibilité renvoie vers /app/billing. Seule la vérification de l’abonnement par les webhooks signés de Stripe accorde les droits du forfait.
GET /api/billing/status
Renvoie le forfait de facturation enregistré, l’état de l’abonnement et la disponibilité de Stripe.
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/json'}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/billing/status')
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
if not cookie_file.is_file():
raise SystemExit('Run session_login first')
(workdir / 'cookie_path').write_text(str(cookie_file))
PY
endpoint=$(<"$workdir/endpoint")
cookie_file=$(<"$workdir/cookie_path")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request GET \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--cookie "$cookie_file" \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" <<'PY'
import json, sys
from pathlib import Path
print(json.dumps(json.loads(Path(sys.argv[1]).read_text()), indent=2))
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/billing/status';
$headers = ['Accept: application/json'];
$cookieFile = required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt');
if (file_exists($cookieFile) && (fileperms($cookieFile) & 0077)) {
throw new RuntimeException('Cookie jar must have mode 600');
}
if (!is_file($cookieFile)) { throw new RuntimeException('Run session_login first'); }
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_COOKIEFILE => $cookieFile,
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
echo json_encode(json_decode($content, true, 512, JSON_THROW_ON_ERROR), JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR) . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/billing/status'
headers = {'Accept': 'application/json'}
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
cookies = http.cookiejar.MozillaCookieJar(str(cookie_file))
if not cookie_file.is_file():
raise SystemExit('Run session_login first')
cookies.load(ignore_discard=True, ignore_expires=False)
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False, cookies=cookies) as client:
response = client.request('GET', base_url + path, headers=headers)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
print(json.dumps(response.json(), indent=2))
POST /api/billing/checkout
Crée une session de paiement intégré pour starter, pro ou business après validation fiscale. Renvoie session_id et client_secret ; ne journalisez pas la réponse. La requête seule ne confirme aucun paiement.
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/json', 'Content-Type': 'application/json', 'Origin': 'https://shotforge.dev'}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/billing/checkout')
(workdir / 'body').write_text(json.dumps({'plan_name': 'pro', 'locale': 'fr'}))
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
if not cookie_file.is_file():
raise SystemExit('Run session_login first')
(workdir / 'cookie_path').write_text(str(cookie_file))
PY
endpoint=$(<"$workdir/endpoint")
cookie_file=$(<"$workdir/cookie_path")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request POST \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--cookie "$cookie_file" \
--data-binary "@$workdir/body" \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" shotforge-checkout.json "$workdir/response_headers" <<'PY'
import json, os, sys
from pathlib import Path
source, target = Path(sys.argv[1]), Path(sys.argv[2])
json.loads(source.read_text())
with target.open('xb') as output:
output.write(source.read_bytes())
target.chmod(0o600)
print(f'Saved private response to {target}')
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/billing/checkout';
$headers = ['Accept: application/json', 'Content-Type: application/json', 'Origin: https://shotforge.dev'];
$cookieFile = required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt');
if (file_exists($cookieFile) && (fileperms($cookieFile) & 0077)) {
throw new RuntimeException('Cookie jar must have mode 600');
}
if (!is_file($cookieFile)) { throw new RuntimeException('Run session_login first'); }
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_COOKIEFILE => $cookieFile,
CURLOPT_POSTFIELDS => json_encode(['plan_name' => 'pro', 'locale' => 'fr'], JSON_THROW_ON_ERROR),
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
json_decode($content, true, 512, JSON_THROW_ON_ERROR);
$target = 'shotforge-checkout.json';
$output = fopen($target, 'xb');
if ($output === false) { throw new RuntimeException('Output already exists or cannot be created'); }
if (fwrite($output, $content) !== strlen($content)) {
fclose($output); throw new RuntimeException('Incomplete output');
}
fclose($output);
chmod($target, 0600);
echo "Saved private response to " . $target . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/billing/checkout'
headers = {'Accept': 'application/json', 'Content-Type': 'application/json', 'Origin': 'https://shotforge.dev'}
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
cookies = http.cookiejar.MozillaCookieJar(str(cookie_file))
if not cookie_file.is_file():
raise SystemExit('Run session_login first')
cookies.load(ignore_discard=True, ignore_expires=False)
payload = {'plan_name': 'pro', 'locale': 'fr'}
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False, cookies=cookies) as client:
response = client.request('POST', base_url + path, headers=headers, json=payload)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
response.json()
target = Path('shotforge-checkout.json')
with target.open('xb') as output:
output.write(response.content)
target.chmod(0o600)
print(f'Saved private response to {target}')
POST /api/billing/portal
Compatibilité locale : renvoie portal_url avec /app/billing pour ouvrir l’espace de facturation ShotForge.
cURL
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
python3 - "$workdir" <<'PY'
import json, os, sys
from pathlib import Path
from urllib.parse import quote, urlencode
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
workdir = Path(sys.argv[1])
headers = {'Accept': 'application/json', 'Origin': 'https://shotforge.dev'}
(workdir / "headers").write_text("".join(f"{key}: {value}\n" for key, value in headers.items()))
(workdir / 'endpoint').write_text('https://shotforge.dev' + '/api/billing/portal')
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
if not cookie_file.is_file():
raise SystemExit('Run session_login first')
(workdir / 'cookie_path').write_text(str(cookie_file))
PY
endpoint=$(<"$workdir/endpoint")
cookie_file=$(<"$workdir/cookie_path")
http_status=$(curl --silent --show-error --connect-timeout 10 --max-time 90 \
--request POST \
--header "@$workdir/headers" \
--output "$workdir/response" --dump-header "$workdir/response_headers" --write-out '%{http_code}' \
--cookie "$cookie_file" \
"$endpoint")
case "$http_status" in 200) ;;
*)
python3 - "$http_status" "$workdir/response" <<'PY'
import json, re, sys
from pathlib import Path
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
raise SystemExit(f'HTTP {sys.argv[1]}: {error_code(Path(sys.argv[2]).read_bytes())}')
PY
exit 1 ;;
esac
python3 - "$workdir/response" <<'PY'
import json, sys
from pathlib import Path
print(json.dumps(json.loads(Path(sys.argv[1]).read_text()), indent=2))
PY
PHP
<?php
declare(strict_types=1);
umask(0077);
function required(string $name, ?string $default = null): string {
$value = getenv($name);
if ($value === false) { $value = $default; }
if ($value === null || ($default === null && trim($value) === '')) {
throw new RuntimeException('Set ' . $name . ' in the environment');
}
return $value;
}
function headerValue(string $value): string {
if (str_contains($value, "\r") || str_contains($value, "\n")) {
throw new RuntimeException('Invalid header value');
}
return $value;
}
function errorCode(string $content): string {
$body = json_decode($content, true);
$detail = is_array($body) ? ($body['detail'] ?? null) : null;
if (is_array($detail)) { return 'validation_error'; }
if (is_string($detail) && preg_match('/^[a-zA-Z0-9_.-]{1,80}$/D', $detail)) {
return $detail;
}
return 'request_failed';
}
$baseUrl = 'https://shotforge.dev';
$path = '/api/billing/portal';
$headers = ['Accept: application/json', 'Origin: https://shotforge.dev'];
$cookieFile = required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt');
if (file_exists($cookieFile) && (fileperms($cookieFile) & 0077)) {
throw new RuntimeException('Cookie jar must have mode 600');
}
if (!is_file($cookieFile)) { throw new RuntimeException('Run session_login first'); }
$curl = curl_init($baseUrl . $path);
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_COOKIEFILE => $cookieFile,
]);
$content = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$mediaType = explode(';', (string) curl_getinfo($curl, CURLINFO_CONTENT_TYPE))[0];
if ($content === false) { curl_close($curl); throw new RuntimeException('Transport failed'); }
curl_close($curl);
$curl = null;
if (!in_array($status, [200], true)) {
throw new RuntimeException('HTTP ' . $status . ': ' . errorCode($content));
}
echo json_encode(json_decode($content, true, 512, JSON_THROW_ON_ERROR), JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR) . "\n";
Python
import http.cookiejar
import json
import os
import re
from pathlib import Path
from urllib.parse import quote
import httpx
os.umask(0o077)
def required(name, default=None):
value = os.environ.get(name, default)
if value is None or (default is None and not value.strip()):
raise SystemExit(f"Set {name} in the environment")
return value
def header_value(value):
if "\r" in value or "\n" in value:
raise SystemExit("Invalid header value")
return value
def error_code(content):
try:
detail = json.loads(content).get('detail')
except (ValueError, AttributeError):
return 'request_failed'
if isinstance(detail, list):
return 'validation_error'
if isinstance(detail, str) and re.fullmatch(r'[a-zA-Z0-9_.-]{1,80}', detail):
return detail
return 'request_failed'
base_url = 'https://shotforge.dev'
path = '/api/billing/portal'
headers = {'Accept': 'application/json', 'Origin': 'https://shotforge.dev'}
cookie_file = Path(required('SHOTFORGE_COOKIE_FILE', './shotforge-cookies.txt'))
if cookie_file.exists() and cookie_file.stat().st_mode & 0o077:
raise SystemExit('Cookie jar must have mode 600')
cookies = http.cookiejar.MozillaCookieJar(str(cookie_file))
if not cookie_file.is_file():
raise SystemExit('Run session_login first')
cookies.load(ignore_discard=True, ignore_expires=False)
with httpx.Client(timeout=httpx.Timeout(90.0, connect=10.0), follow_redirects=False, cookies=cookies) as client:
response = client.request('POST', base_url + path, headers=headers)
if response.status_code not in (200,):
raise SystemExit(f'HTTP {response.status_code}: {error_code(response.content)}')
print(json.dumps(response.json(), indent=2))
Réponses et erreurs
Les échecs JSON utilisent un code detail stable. Les erreurs de validation peuvent renvoyer le tableau detail structuré de FastAPI. Ne dépendez jamais d’un texte destiné à l’affichage.
{"detail":"session_required"}
| HTTP | detail | Description |
|---|---|---|
| 400 | quota_exceeded | Le quota mensuel est épuisé. Attendez la remise à zéro UTC ou changez de forfait. |
| 400 | width_exceeds_plan | La largeur demandée dépasse le maximum du forfait actif. |
| 400 | unknown_og_template | Le modèle Open Graph demandé n’existe pas. |
| 400 | url_must_be_http / invalid_dimensions / text_too_long | Un champ de la démonstration anonyme est invalide : schéma d’URL, dimensions ou longueur de texte. |
| 400 | too_many_api_keys | Le compte a atteint sa limite de clés API actives. Révoquez une clé inutilisée avant d’en créer une nouvelle. |
| 401 | not_authenticated / session_required / invalid_api_key / invalid_token / token_revoked / invalid_credentials | Identifiant absent, invalide, expiré, révoqué ou inactif. |
| 401 | invalid_refresh_token / refresh_token_expired / token_reuse_detected | Le refresh token est invalide, expiré, révoqué ou réutilisé. Reconnectez-vous après une détection de réutilisation. |
| 403 | invalid_password / free_og_template_not_available | La vérification du mot de passe a échoué, ou le modèle Open Graph anonyme demandé exige une authentification. |
| 403 | pro_template_required | Ce modèle Open Graph nécessite Pro, Business ou un essai Pro actif. Free et Starter donnent accès aux 41 modèles de base. |
| 403 | origin_mismatch | Les routes réservées à une session navigateur refusent les origines tierces. Les mutations de facturation exigent l’en-tête Origin correspondant exactement à l’origine ShotForge, y compris pour un appel de serveur à serveur. |
| 403 | full_page_not_in_plan | La capture avec défilement n’est pas disponible avec le forfait actif. |
| 403 | auth_render_not_in_plan | Le rendu d’une page cible authentifiée n’est pas disponible avec le forfait actif. |
| 403 | pdf_not_in_plan / og_not_in_plan | Le type de sortie demandé n’est pas disponible avec le forfait actif. |
| 404 | not_found | La ressource demandée n’existe pas ou n’appartient pas à ce compte. |
| 404 | no_billing_account / billing_object_mismatch / no_active_subscription | Le compte de facturation ou l’objet demandé est introuvable. Vérifiez le compte connecté et la référence utilisée. |
| 409 | email_already_registered | Un compte existe déjà pour cette adresse email. |
| 409 | billing_checkout_pending / billing_cleanup_stale | Une opération de facturation ou de paiement est encore en attente. Attendez sa résolution avant de relancer la demande de suppression du compte. |
| 422 | url_not_allowed / navigation_failed / render_timeout / page_too_large / authentication_failed / render_failed | Échec de rendu sécurisé : destination interdite, navigation impossible, timeout, page trop grande, identifiants cibles refusés ou erreur navigateur. |
| 422 | structured validation detail array | Un champ est absent, hors limites ou contient une valeur non prise en charge. |
| 422 | invalid_plan / billing_cancellation_invalid / billing_invoice_invalid / billing_invoice_cursor_invalid / billing_setup_invalid / billing_preview_invalid | Le forfait demandé ou les champs de facturation sont invalides. Vérifiez le corps de la requête avant de la renvoyer. |
| 423 | account_locked | Le compte est temporairement verrouillé après plusieurs échecs de connexion. |
| 429 | rate_limit_exceeded | Limite de débit dépassée. Attendez la durée Retry-After avant de réessayer. |
| 500 | internal_error | Erreur serveur inattendue. Réessayez avec un délai progressif ; contactez le support si elle persiste. |
| 502 | billing_unavailable / billing_tax_provider_unavailable | Le prestataire de facturation n’a pas pu terminer l’opération. Réessayez plus tard ou contactez le support si le problème persiste. |
| 503 | stripe_not_configured / plan_not_synced_to_stripe / billing_tax_configuration_required | Le paiement Stripe est indisponible ou sa configuration est incomplète. Réessayez plus tard ou contactez le support. |
| 502 / 503 | billing_cleanup_failed / billing_cleanup_unavailable | Le prestataire de facturation externe n’a pas pu terminer le nettoyage demandé. Réessayez plus tard ou contactez le support. |
Checklist d’intégration en production
- Utilisez --fail-with-body ou l’équivalent : un corps d’erreur enregistré en .png reste du JSON.
- Réessayez les 429, erreurs réseau et 5xx transitoires avec un backoff exponentiel borné ; ne réessayez pas aveuglément les erreurs 4xx de validation ou de forfait.
- Configurez un timeout client supérieur à celui du rendu serveur : au moins 45 secondes, davantage pour les pages complètes.
- Gardez les clés API et identifiants des sites cibles côté serveur. Ne les placez jamais dans du JavaScript navigateur, une application mobile, les logs, les URL, l’historique du shell ou les arguments d’un processus.
- Diffusez les réponses binaires directement vers le stockage ou le client au lieu de convertir de gros fichiers en JSON/base64.
- Un nouvel essai crée un nouveau rendu et peut consommer du quota si la première réponse réussie a été perdue. Ne réessayez que si le résultat initial est inconnu et nécessaire.