← Back to blog

Auto-Generate Link Previews with the OGSnap API: A Developer's Guide

Link previews — the rich cards that appear when you paste a URL into Slack, Discord, iMessage, WhatsApp, or Notion — are one of the highest-leverage UI details in modern web apps. A bare blue link gets a fraction of the clicks that a card with a headline, description, and image gets, which is why every major chat platform, CMS, and social network spends engineering effort on "unfurling" URLs.

If you've ever built this yourself, you know the pain: fetching remote pages, parsing og: and twitter: meta tags by hand, handling missing or relative image URLs, deciding what to do when a page has no Open Graph tags at all, and then caching everything so you don't hammer the target site. The OGSnap API from FetchAPI collapses that entire project into a single HTTP GET.

This guide shows you how to auto-generate link previews in your app, your chat bot, and your AI agent pipeline — with production patterns that survive real-world pages.

What OGSnap Returns

OGSnap reads a URL server-side, parses its Open Graph tags, Twitter Cards, and JSON-LD structured data, and returns them as one clean JSON document:

curl "https://fetchapi.tech/v1/ogsnap?url=https://github.com/NousResearch/hermes-agent"
{
  "og": {
    "title": "NousResearch/hermes-agent",
    "description": "Hermes Agent is an open-source AI agent that turns natural language into action...",
    "image": "https://opengraph.githubassets.com/.../og-image.png",
    "url": "https://github.com/NousResearch/hermes-agent"
  },
  "twitter": {
    "card": "summary_large_image",
    "title": "NousResearch/hermes-agent",
    "description": "...",
    "image": "..."
  },
  "jsonld": {
    "@type": "WebSite",
    "name": "GitHub"
  }
}

Three data sources, one request. The og object is your primary preview source, twitter is the X/Twitter variant (often identical, occasionally richer), and jsonld gives you structured entities — products, articles, recipes, organizations — that are gold for SEO tooling and content intelligence. No signup is required for the free tier, and the endpoint works with plain curl.

Use Case 1: Rich link previews in your own app

The most common need: a user pastes a URL into your app (a comment box, a shared-links feed, a bookmarking tool), and you want to render a preview card under the input.

Call OGSnap from your backend — not the browser — so your API key stays private and you control caching:

import requests

def preview_for(url: str) -> dict:
    r = requests.get("https://fetchapi.tech/v1/ogsnap",
                     params={"url": url}, timeout=10)
    r.raise_for_status()
    data = r.json()["og"]
    return {
        "title": data.get("title") or url,
        "description": data.get("description", ""),
        "image": data.get("image", ""),
        "url": data.get("url") or url,
    }

Your frontend then renders the card. A few rendering rules that separate polished previews from janky ones:

Use Case 2: An unfurl bot for Slack or Discord

Chat platforms have native unfurling for well-known domains, but for internal tools, staging URLs, and private links you usually want your own bot. Here's a minimal Slack slash-command handler that turns /preview https://... into a rich message:

curl -s "https://fetchapi.tech/v1/ogsnap?url=https://example.com/blog/post" \
  | jq '{title: .og.title, description: .og.description, image: .og.image}'

Then post the result to your Slack webhook:

curl -s -X POST -H 'Content-type: application/json' \
  --data '{
    "text": "Link preview",
    "attachments": [{
      "title": "Example Blog Post",
      "title_link": "https://example.com/blog/post",
      "text": "A short description pulled from the Open Graph tags.",
      "image_url": "https://example.com/og-image.png"
    }]
  }' https://hooks.slack.com/services/T000000/B000000/XXXXXXXX

The pattern is identical for Discord (embeds instead of attachments). Because OGSnap normalizes Twitter Cards too, the same payload shape works for platforms that prefer twitter: tags — you don't need to know which format the target site uses.

Use Case 3: Give your AI agent a link-reading tool

Agents browse the web blindly unless you hand them good tools. An OGSnap tool lets your LLM look before it leaps: fetch the title, description, and image of a URL to decide whether a link is relevant, before spending tokens on the full page. Here's the pattern as an agent tool definition:

{
  "name": "get_link_preview",
  "description": "Fetch the Open Graph title, description, and image for a URL. Use this to decide if a link is worth reading before fetching full content.",
  "parameters": {
    "type": "object",
    "properties": {
      "url": { "type": "string", "description": "The URL to preview" }
    },
    "required": ["url"]
  }
}

The implementation is the same one-liner curl from above. Pair it with Markdownify for a complete link-intake pipeline: OGSnap decides, Markdownify reads, the YouTube Transcript API handles video links. One agent, three tools, zero HTML parsing. This is exactly the kind of "read the web" capability that turns a chatbot into a research assistant that can triage a dozen links in one conversation turn.

Use Case 4: SEO and social-card auditing

If you run a content site, your Open Graph tags are your social media presence — a missing og:image means a bare link on X, LinkedIn, and Facebook. OGSnap makes auditing trivial, both for your own pages and your competitors':

for url in \
  https://fetchapi.tech \
  https://fetchapi.tech/docs \
  https://fetchapi.tech/blog; do
  echo "== $url"
  curl -s "https://fetchapi.tech/v1/ogsnap?url=$url" \
    | jq -r '"title: " + (.og.title // "MISSING") + " | image: " + (.og.image // "MISSING")'
done

Run that weekly in a cron job and you'll catch a broken og:image before a viral share does. The jsonld field extends this into structured-data auditing: check that articles expose headline, datePublished, and author, which is what powers rich results in Google.

Best Practices for Production

Wrap-Up

Link previews shouldn't require a weekend of HTML parsing. OGSnap gives you Open Graph, Twitter Cards, and JSON-LD for any URL in one GET — ready for apps, chat bots, AI agents, and SEO tooling. The free tier means you can ship the first version today with zero setup.

Try it now: curl "https://fetchapi.tech/v1/ogsnap?url=https://example.com". For the rest of the suite — YouTube Transcript API, Markdownify, and DiffCheck — check the docs and start building.