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:title | Title of the content | Yes |
og:type | Type of content (website, article, etc.) | Yes |
og:image | URL of the preview image | Yes |
og:url | Canonical URL of the page | Yes |
og:description | Brief description of the content | Recommended |
og:site_name | Name of the website | Recommended |
Using the Open Graph API
TinyFn provides an endpoint to generate Open Graph meta tags:
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"
}
{
"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
- Use high-quality images: At least 1200x630px for best results
- Keep titles under 60 characters: Prevents truncation on most platforms
- Write compelling descriptions: 155-200 characters for optimal display
- 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