URL Metadata API: Build Link Previews From Any URL

Published: · APIs in this article: URL Metadata, Social Image Generator

Paste a link into Slack, Discord or iMessage and a neat card appears: title, short description, image, site icon. Users now expect the same in every app that accepts links: chat, comments, CMS editors, bookmark managers, CRMs.

Building that card looks easy until you try. You need to fetch an arbitrary URL safely, follow redirects, cap the download size, parse messy HTML, fall back from Open Graph to Twitter Card to plain <meta> tags, resolve relative image URLs and find a usable favicon.

This guide shows how to get all of that from one call to the APIBox /v1/url-metadata endpoint, and how to turn the response into a link preview card.

What the endpoint returns

Give it a public url. The API fetches the page, follows redirects and parses the <head>. The top-level fields are already resolved for you:

Field Where it comes from
title, description Open Graph → Twitter Card → standard meta tags / <title>
image, image_alt og:image → twitter:image, made absolute
site_name, type, locale, lang OG tags and <html lang>
canonical <link rel="canonical">
favicon, icons Declared icons (first one as favicon), else /favicon.ico
author, keywords, published_time, theme_color, robots Standard meta tags
feeds RSS / Atom links
alternates hreflang alternate URLs
json_ld Up to 5 parsed JSON-LD blocks

You also get the raw open_graph, twitter_card and meta objects, plus fetch details: final_url, HTTP status, content_type, the redirects chain and response_ms.

Limits worth knowing up front

  • Results are cached for 1 hour per URL. Add fresh=true to refetch, for example right after you change your own meta tags.
  • Pages are read up to 1.5 MB, with a 10-second timeout and at most 8 redirects.
  • Only public http/https hosts; the URL can be up to 4,096 characters. Private IPs are blocked, and so is the API's own host (apibox.io.vn returns 400 host_not_allowed).
  • For non-HTML URLs (a PDF, an image) only the basic fields are returned.
  • The API reads the HTML the server sends; it does not execute JavaScript. Sites that inject their meta tags client-side may return less data. (Most sites set OG tags server-side precisely because social crawlers don't run JavaScript either.)
  • No oEmbed: if you need embeddable players (YouTube, X posts), use the provider's oEmbed endpoint alongside this.

Setup

Create a free APIBox account (Free plan: 1,000 requests per month, 30 per minute, no card) and generate an API key:

export APIBOX_KEY="your_key_here"

Send the key as Authorization: Bearer, an x-api-key header, or an api_key query parameter. Use a header in server code.

1. Fetch metadata for a URL (curl)

curl -s -G https://apibox.io.vn/v1/url-metadata \
  -H "Authorization: Bearer $APIBOX_KEY" \
  --data-urlencode "url=https://github.com"

Response on 2026-11-25 (long strings and the meta object truncated):

{
  "url": "https://github.com/",
  "final_url": "https://github.com/",
  "status": 200,
  "content_type": "text/html; charset=utf-8",
  "redirects": [],
  "response_ms": 219,
  "title": "GitHub · Change is constant. GitHub keeps you ahead. · GitHub",
  "description": "Join the world's most widely adopted, AI-powered developer platform where millions of developers, businesses, and the largest open source community build software that advances humanity.",
  "image": "https://images.ctfassets.net/8aevphvgewt8/76epZKB2wF998m4e4bLLXn/c505f20b00ec70b88b1be5aec42c4be4/OG_image.jpg",
  "image_alt": "Join the world's most widely adopted, AI-powered developer platform where millions of developers, businesses, and the largest open source community build software that advances humanity.",
  "site_name": "GitHub",
  "type": "object",
  "locale": null,
  "lang": "en",
  "canonical": "https://github.com/",
  "author": null,
  "keywords": [],
  "published_time": null,
  "theme_color": "#1e2327",
  "robots": null,
  "favicon": "https://github.githubassets.com/favicons/favicon.png",
  "icons": [
    { "href": "https://github.githubassets.com/favicons/favicon.png", "rel": "alternate icon", "type": "image/png" },
    { "href": "https://github.githubassets.com/favicons/favicon.svg", "rel": "icon", "type": "image/svg+xml" }
  ],
  "feeds": [],
  "alternates": ["https://github.com/", "https://github.com/?locale=pt-br", "https://github.com/?locale=es-419", "https://github.com/?locale=ja", "… (truncated, 8 in total)"],
  "open_graph": {
    "image": "https://images.ctfassets.net/8aevphvgewt8/76epZKB2wF998m4e4bLLXn/c505f20b00ec70b88b1be5aec42c4be4/OG_image.jpg",
    "image:alt": "Join the world's most widely adopted, AI-powered developer platform… (truncated)",
    "site_name": "GitHub",
    "type": "object",
    "title": "GitHub · Change is constant. GitHub keeps you ahead. · GitHub",
    "url": "https://github.com/",
    "description": "Join the world's most widely adopted, AI-powered developer platform… (truncated)"
  },
  "twitter_card": {
    "image": "https://images.ctfassets.net/8aevphvgewt8/76epZKB2wF998m4e4bLLXn/c505f20b00ec70b88b1be5aec42c4be4/OG_image.jpg",
    "site": "@github",
    "card": "summary_large_image",
    "title": "GitHub · Change is constant. GitHub keeps you ahead. · GitHub",
    "description": "Join the world's most widely adopted, AI-powered developer platform… (truncated)"
  },
  "meta": {
    "viewport": "width=device-width",
    "description": "Join the world's most widely adopted, AI-powered developer platform… (truncated)",
    "theme-color": "#1e2327",
    "color-scheme": "light dark",
    "…": "(truncated: about 40 site-specific meta tags in total)"
  },
  "json_ld": []
}

The raw meta object contains every <meta name> on the page. On GitHub that is about 40 entries, mostly internal ones. Read the resolved top-level fields for cards, and dig into meta only when you need a specific tag.

For a preview card you only need five fields: title, description, image, favicon and site_name. The rest is there when you need it: twitter_card.card tells you whether the site prefers a large image (summary_large_image) or a small thumbnail (summary); theme_color is a nice accent for the card border.

Never call the API from the browser: your key would be visible to everyone. Put a tiny endpoint in your backend and let the frontend call that:

// Node 18+ / any fetch-capable runtime
const KEY = process.env.APIBOX_KEY;

export async function linkPreview(url) {
  const api = new URL('https://apibox.io.vn/v1/url-metadata');
  api.searchParams.set('url', url);
  const r = await fetch(api, { headers: { Authorization: `Bearer ${KEY}` } });
  if (!r.ok) return null; // no card is better than a broken card
  const m = await r.json();
  if (m.status >= 400) return null;
  return {
    url: m.canonical || m.final_url,
    title: m.title,
    description: m.description,
    image: m.image,
    icon: m.favicon,
    site: m.site_name || new URL(m.final_url).hostname,
    large: m.twitter_card?.card === 'summary_large_image',
  };
}

console.log(await linkPreview('https://github.com'));

Output:

{
  url: 'https://github.com/',
  title: 'GitHub · Change is constant. GitHub keeps you ahead. · GitHub',
  description: "Join the world's most widely adopted, AI-powered developer platform where millions of developers, businesses, and the largest open source community build software that advances humanity.",
  image: 'https://images.ctfassets.net/8aevphvgewt8/76epZKB2wF998m4e4bLLXn/c505f20b00ec70b88b1be5aec42c4be4/OG_image.jpg',
  icon: 'https://github.githubassets.com/favicons/favicon.png',
  site: 'GitHub',
  large: true
}

Rendering tips:

  • Fallbacks. Many pages have no image. Show a compact card with the favicon instead of a broken image.
  • Truncate. Clamp description to two or three lines with CSS; some sites stuff long paragraphs into it.
  • Proxy or cache images. Hot-linking third-party images leaks your users' IPs to those sites and breaks when the image moves. Downloading the image once and serving it from your own storage is more robust.
  • Store the card. Save the preview with the message or post. Re-fetching on every view wastes quota and makes old messages change when the target page changes.

3. Audit your own Open Graph tags (Python)

The same data makes a quick pre-launch check: are all your important pages shareable? Loop over your sitemap URLs and flag pages missing an image, description or canonical:

import os, time, requests

KEY = os.environ["APIBOX_KEY"]
H = {"Authorization": f"Bearer {KEY}"}

urls = ["https://github.com/", "https://ogp.me/", "https://example.com/"]

for u in urls:
    r = requests.get("https://apibox.io.vn/v1/url-metadata",
                     params={"url": u, "fresh": "true"}, headers=H, timeout=30)
    r.raise_for_status()
    m = r.json()
    missing = [k for k in ("title", "description", "image", "canonical") if not m.get(k)]
    print(u, "OK" if not missing else f"missing: {', '.join(missing)}")
    time.sleep(2)  # stay well under 30 requests/minute on the Free plan

Output on 2026-11-25 (swap in your own sitemap URLs):

https://github.com/ OK
https://ogp.me/ missing: canonical
https://example.com/ missing: description, image, canonical

Even the Open Graph protocol's own site has no <link rel="canonical">. That is fine for a one-page site, but on a real site with tracking parameters and www/non-www variants it is worth fixing.

fresh=true matters here: you want the page as it is now, not a copy cached an hour ago before your fix.

4. Pages with no og:image? Generate one

If the audit shows pages without a preview image, APIBox also has /v1/og-image, which draws a 1200×630 PNG (or JPEG) from a title, optional subtitle, tag and site name, with light, dark or brand themes and several sizes (og, twitter, linkedin, square, story).

curl -s -G https://apibox.io.vn/v1/og-image \
  -H "Authorization: Bearer $APIBOX_KEY" \
  --data-urlencode "title=How we cut our build time in half" \
  --data-urlencode "site=example.com" \
  --data-urlencode "theme=dark" \
  -o og-build-time.png

This returned HTTP 200, Content-Type: image/png, a 1200×630 PNG of about 64 KB: the title in large white type on a dark background, with "example.com" at the bottom.

Generate the image at publish time, upload it to your own storage or CDN, and put that URL in <meta property="og:image">. Don't put an API URL containing your key into public HTML.

Build it yourself or call an API?

You can absolutely build this. Open-source parsers such as metascraper (Node) or extruct and BeautifulSoup (Python) do the parsing well. The parts people underestimate are around the parser:

  • Safe fetching. A link preview fetcher downloads URLs supplied by users. Without care, that is a server-side request forgery (SSRF) hole into your internal network. You need private-IP blocking, size caps, timeouts and redirect limits.
  • Fallback logic. Open Graph, Twitter Card, plain meta tags and <title> disagree more often than you'd think.
  • Caching. Popular links get pasted again and again.

If you already run a hardened fetcher, a library is enough. If you don't, an API that does the fetching on its own infrastructure keeps that risk out of your servers. Several hosted services exist; compare their fields and limits against what your cards need.

FAQ

How do I get the Open Graph image of a URL? Call /v1/url-metadata?url=... and read image (og:image, falling back to twitter:image), or the full open_graph object.

Are results cached? Yes, for 1 hour per URL. Add fresh=true to fetch the page again.

Does it follow redirects? Yes, up to 8. The response contains final_url and the redirects chain with each status code.

Can I call it from the browser? Technically yes, but your API key would be public. Call it from your backend.

Does it return oEmbed data? No. It returns Open Graph, Twitter Card, standard meta tags, icons, feeds and JSON-LD.

Get started

👉 Get a free API key – 1,000 requests per month, no credit card.

Full reference: URL Metadata API docs and OG Image API docs. Try it without code: Open Graph & meta tag checker.

More articles

All guides →