The 3-line version (requests)
import requests
r = requests.get(
'https://api.aisnapapi.com/v1/screenshot',
params={'url': 'https://example.com'},
headers={'Authorization': 'Bearer YOUR_API_KEY'}
)
open('shot.png', 'wb').write(r.content)
The response body is raw image bytes. No JSON, no base64.
Async with httpx
import httpx, asyncio
async def snap(url):
async with httpx.AsyncClient() as c:
r = await c.get(
'https://api.aisnapapi.com/v1/screenshot',
params={'url': url, 'full_page': 'true'},
headers={'Authorization': 'Bearer YOUR_API_KEY'}
)
return r.content
png = asyncio.run(snap('https://news.ycombinator.com'))
Django view: proxy a screenshot to the user
import os, requests
from django.http import HttpResponse
def screenshot(request):
target = request.GET.get('url')
r = requests.get(
'https://api.aisnapapi.com/v1/screenshot',
params={'url': target},
headers={'Authorization': f'Bearer {os.environ["SNAPAPI_KEY"]}'},
stream=True
)
return HttpResponse(r.iter_content(8192), content_type='image/png')
FastAPI endpoint that returns a screenshot
import os, httpx
from fastapi import FastAPI
from fastapi.responses import StreamingResponse
app = FastAPI()
@app.get('/screenshot')
async def capture(url: str):
client = httpx.AsyncClient()
r = await client.get(
'https://api.aisnapapi.com/v1/screenshot',
params={'url': url, 'width': 1280},
headers={'Authorization': f'Bearer {os.environ["SNAPAPI_KEY"]}'}
)
return StreamingResponse(iter([r.content]), media_type='image/png')
Generate a PDF from any URL
import requests
r = requests.get(
'https://api.aisnapapi.com/v1/screenshot',
params={'url': 'https://en.wikipedia.org/wiki/Python_(programming_language)', 'format': 'pdf'},
headers={'Authorization': 'Bearer YOUR_API_KEY'}
)
open('page.pdf', 'wb').write(r.content)
Common gotchas
- Use
params=, not f-string interpolation. requests URL-encodes for you and you'll avoid encoding bugs.
- Single-page apps: if you get a blank screenshot of a React/Vue site, add
'delay': 1500 to your params.
- Stream in handlers: use
stream=True + iter_content in Django/Flask so big screenshots don't load fully into memory.
- Don't ship secrets: store
SNAPAPI_KEY in env, never commit it.
- Cache: if you're using screenshots for OG images, cache them at your CDN. One screenshot per unique image, not per pageview.