Link Preview API

Generate rich link previews with screenshot thumbnails and scraped metadata for any URL. One API call returns the title, description, image, and a full-page screenshot.

Start Free — 200 previews/month

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.

Link Preview API Open Graph Extraction

The SnapAPI scrape endpoint extracts Open Graph metadata including og:title, og:description, og:image, og:url, and og:type from any web page, providing the structured data needed for rich link preview cards. Pages that implement Open Graph tags correctly will have all preview metadata available in a single scrape call without requiring a screenshot: the og:image provides the preview image, og:title provides the card headline, and og:description provides the preview text. For pages missing Open Graph tags, fall back to the standard HTML title element and meta description tag which the scrape endpoint also returns. Use the og:image URL directly in your preview card if it is an absolute URL pointing to an existing image, checking that the URL scheme is https and the domain matches the source page domain to filter out placeholder or broken og:image values before using them in your preview display. Generate a screenshot as the fallback image only when no usable og:image is available from the scrape response, making the screenshot the exception rather than the rule for pages with well-formed metadata.

Link Preview API for Slack-Style Message Previews

Messaging applications generate link preview cards when users post URLs in messages, showing a compact card with the page title, a description snippet, and a thumbnail image directly in the message thread. Implement link preview generation as an asynchronous background task triggered after message creation: when a user sends a message containing a URL pattern, extract the URL, enqueue a link preview generation task with the URL and message ID, and have background workers call SnapAPI scrape and screenshot endpoints to generate the preview data. Store the preview data associated with the message, update the message record with the preview metadata, and push a real-time update to the message channel so clients replace the bare URL display with the rich preview card. Implement a URL expansion safelist or blocklist to control which domains trigger preview generation: always generate previews for trusted domains and content types, and skip generation for domains known to have privacy-sensitive content or that block web scraping. Rate limit link preview generation per user or per conversation to prevent a single user from exhausting your SnapAPI request budget by posting many URLs in rapid succession.

Link Preview API Performance and Scaling

At scale, link preview generation requires careful management of API request budgets, cache hit rates, and background worker capacity. Track the cache hit rate for link preview requests: a high cache hit rate above ninety percent indicates that most preview requests are served from cache without API calls, while a low cache hit rate suggests that cache TTLs are too short or that the URL population is too diverse for effective caching. Measure the p95 and p99 latency of link preview generation jobs to ensure background workers are keeping up with the rate at which users post new URLs. If worker latency is high, add more worker processes or increase worker concurrency to reduce the queue backlog. Monitor SnapAPI request consumption per day to track usage against your plan limit, setting an alert at eighty percent consumption to allow time to upgrade before hitting the limit. For applications with highly variable link preview traffic, consider a tiered generation strategy: immediately generate previews for URLs posted by high-engagement users and defer or skip generation for URLs posted by low-engagement users, conserving API credits for the previews most likely to be viewed. Register at snapapi.pics/register to start with two hundred free link preview requests per month and upgrade as your application grows.