What is a Link Preview API?
A link preview API generates the visual and textual preview displayed when a URL is shared in a messaging app, social platform, or content tool. When you paste a URL in Slack, iMessage, or Twitter, the platform fetches a preview showing the page title, description, and an image. A link preview API automates this preview generation programmatically for URLs in your application. SnapAPI generates link previews by combining two calls: the scrape endpoint extracts the page title, meta description, and og:image URL from the rendered page, and the screenshot endpoint captures a full-page screenshot as a visual thumbnail if no og:image is available. Together these provide all the data needed to render a rich link preview: the title for the headline, the description for the preview text, and either the og:image or the screenshot for the visual thumbnail. Applications that need link preview functionality can call both endpoints with a single API key without adding a separate link preview service to their stack.
Building a Link Preview with the SnapAPI Scrape Endpoint
The SnapAPI scrape endpoint returns JSON containing the page title, meta description, and full page text for any URL. Use the scrape endpoint as the first step in link preview generation to retrieve the textual metadata. The response JSON includes the title field from the page head, the description from the meta description tag or og:description tag, and optionally the og:image URL if one is defined in the page head. If the og:image field is present in the scrape response, use it directly as the preview image URL without needing to call the screenshot endpoint, saving an API request for pages that have properly defined Open Graph images. Only fall back to generating a screenshot thumbnail when the scrape response does not include a usable og:image URL, making screenshot generation the fallback rather than the default and reducing API cost for pages with well-formed metadata.
import requests
API_KEY = "your_api_key"
BASE = "https://api.snapapi.pics"
HEADERS = {"Authorization": f"Bearer {API_KEY}"}
def link_preview(url):
# Step 1: scrape metadata
scrape = requests.get(BASE + "/scrape", params={"url": url}, headers=HEADERS, timeout=30)
scrape.raise_for_status()
data = scrape.json()
preview = {
"url": url,
"title": data.get("title", ""),
"description": data.get("description", ""),
"image": data.get("og_image"), # use og:image if present
}
# Step 2: screenshot only if no og:image
if not preview["image"]:
shot = requests.get(
BASE + "/screenshot",
params={"url": url, "format": "jpeg", "quality": 80, "width": 1200},
headers=HEADERS, timeout=30,
)
shot.raise_for_status()
# store bytes to CDN and set URL
preview["image"] = upload_to_cdn(shot.content, url)
return preview
Caching Link Previews for Performance
Link preview generation involves network requests to SnapAPI and potentially to a CDN upload step, making it too slow to perform synchronously on every page load. Cache link preview results with a TTL that balances freshness with performance: use Redis or Memcached with a cache key derived from the URL hash and store the complete preview JSON including title, description, and image URL. Set TTLs of one to twenty-four hours depending on how frequently the target URLs are expected to change: short TTLs for news and frequently updated content, longer TTLs for stable documentation and product pages. Implement lazy caching that generates the preview on the first request and serves from cache on subsequent requests, so users only experience preview generation latency once per URL per cache period. For applications that import large URL collections, implement background preview generation that populates the cache for all imported URLs asynchronously after import, so previews are ready before users view the imported content.
Link Preview API Use Cases
Messaging and collaboration tools display link previews when users share URLs in messages, showing a thumbnail and metadata card below the message text without requiring the recipient to visit the link to understand its content. Bookmarking and read-later applications generate link preview thumbnails for saved URLs, providing a visual grid view that helps users visually identify and navigate their saved content. Knowledge base and wiki tools display visual link cards for external URLs referenced in documents, enriching plain URL links with contextual preview information. CRM and sales tools generate link previews for URLs added to contact and deal records, giving sales team members a visual preview of linked content including competitor pages, news articles, and prospect websites without leaving the CRM interface. Content curation and newsletter tools display link preview cards for referenced articles and resources, providing readers with visual context about linked content before they click through.
Get Started with Link Preview API
Register at snapapi.pics/register for a free account with two hundred requests per month at no cost. The link preview workflow uses the scrape endpoint for metadata and the screenshot endpoint for thumbnail images, both available under the same API key and the same free tier allocation. Documentation at snapapi.pics/docs covers both endpoints with code examples in JavaScript, Python, Go, PHP, Swift, and Kotlin. Official SDKs in all six languages are available on GitHub at github.com/Sleywill and in standard package registries, providing typed function wrappers for both the scrape and screenshot endpoints used in the link preview workflow.