Call Snapshot Site with HTTPX
The model accepts a known page key and the server constructs the provider request.
import os
import httpx
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
app = FastAPI()
PAGES = {
"pricing": "https://example.com/pricing",
"docs": "https://example.com/docs",
}
class CaptureRequest(BaseModel):
page_id: str
@app.post("/captures")
async def create_capture(payload: CaptureRequest):
url = PAGES.get(payload.page_id)
if not url:
raise HTTPException(status_code=400, detail="Unknown page")
async with httpx.AsyncClient(timeout=45) as client:
response = await client.post(
"https://api.prod.ss.snapshot-site.com/api/v1/screenshot",
headers={"x-snapshotsiteapi-key": os.environ["SNAPSHOT_SITE_API_KEY"]},
json={
"url": url,
"format": "webp",
"width": 1440,
"height": 900,
"fullSize": True,
},
)
response.raise_for_status()
return response.json()
