Open Graph Generator API: The Complete Guide

Want your content to look great when shared on social media? This guide covers everything you need to know about generating Open Graph tags via API, including required properties, social platform requirements, and implementation examples.

What is Open Graph?

Open Graph is a protocol created by Facebook that enables web pages to become rich objects in social graphs. When you share a link on social media, Open Graph tags determine the title, description, and image that appear in the preview.

Open Graph tags look like: <meta property="og:title" content="Your Page Title">

Essential OG Properties

The most important Open Graph properties are:

Property Description Required
og:titleTitle of the contentYes
og:typeType of content (website, article, etc.)Yes
og:imageURL of the preview imageYes
og:urlCanonical URL of the pageYes
og:descriptionBrief description of the contentRecommended
og:site_nameName of the websiteRecommended
Pro Tip: Always include all required properties and test your tags using Facebook's Sharing Debugger before launching.

Using the Open Graph API

TinyFn provides an endpoint to generate Open Graph meta tags:

API Request
POST https://api.tinyfn.io/v1/generate/opengraph
Headers: X-API-Key: your-api-key
Content-Type: application/json

{
  "title": "My Amazing Article",
  "description": "Learn how to build amazing things",
  "url": "https://example.com/article",
  "image": "https://example.com/image.jpg",
  "type": "article",
  "site_name": "My Website"
}
Response
{
  "html": "<meta property=\"og:title\" content=\"My Amazing Article\">\n<meta property=\"og:description\" content=\"Learn how to build amazing things\">\n<meta property=\"og:url\" content=\"https://example.com/article\">\n<meta property=\"og:image\" content=\"https://example.com/image.jpg\">\n<meta property=\"og:type\" content=\"article\">\n<meta property=\"og:site_name\" content=\"My Website\">",
  "tags": {
    "og:title": "My Amazing Article",
    "og:description": "Learn how to build amazing things",
    "og:url": "https://example.com/article",
    "og:image": "https://example.com/image.jpg",
    "og:type": "article",
    "og:site_name": "My Website"
  }
}

Parameters

Parameter Type Description
title string Page title (required)
description string Page description (required)
url string Canonical URL (required)
image string Preview image URL (required)
type string Content type: website, article, product (default: website)
include_twitter boolean Include Twitter Card tags (default: true)

Code Examples

JavaScript / Node.js

const response = await fetch('https://api.tinyfn.io/v1/generate/opengraph', {
  method: 'POST',
  headers: {
    'X-API-Key': 'your-api-key',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    title: 'My Blog Post',
    description: 'An interesting article about APIs',
    url: 'https://mysite.com/blog/post',
    image: 'https://mysite.com/images/og-image.jpg',
    type: 'article'
  })
});
const { html } = await response.json();
// Insert into page head

Python

import requests

response = requests.post(
    'https://api.tinyfn.io/v1/generate/opengraph',
    json={
        'title': 'My Product Page',
        'description': 'The best product ever',
        'url': 'https://shop.com/product/123',
        'image': 'https://shop.com/images/product.jpg',
        'type': 'product'
    },
    headers={'X-API-Key': 'your-api-key'}
)
data = response.json()
print(data['html'])

Platform Requirements

  • Facebook: Minimum image size 200x200px, recommended 1200x630px
  • Twitter: Supports Summary Card and Large Image Card formats
  • LinkedIn: Recommended image ratio 1.91:1 (1200x627px)
  • Pinterest: Vertical images work best (2:3 ratio)

Best Practices

  1. Use high-quality images: At least 1200x630px for best results
  2. Keep titles under 60 characters: Prevents truncation on most platforms
  3. Write compelling descriptions: 155-200 characters for optimal display
  4. Test before publishing: Use platform debuggers to preview

Use via MCP

Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:

{
  "mcpServers": {
    "tinyfn-generate": {
      "url": "https://api.tinyfn.io/mcp/generate/",
      "headers": {
        "X-API-Key": "your-api-key"
      }
    }
  }
}

See all generator tools available via MCP in our Generator MCP Tools for AI Agents guide.

Try the Open Graph API

Get your free API key and start generating perfect social previews.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key