How It Works
Our REST API accepts JSON input and returns a PNG image. It's that simple.
POST
https://ogimageapi.io/api/generate
Request
POST /api/generate
Content-Type: application/json
X-API-Key: your_api_key
{
"title": "Your Image Title",
"subtitle": "Optional subtitle text",
"theme": "dark",
"template": "default"
}
Response
Content-Type: image/png
Content-Length: 42568
[PNG binary data]
JSON Schema
Full specification of accepted parameters:
{
// Required
"title": string, // Main text (max 100 chars)
// Optional
"subtitle": string, // Secondary text (max 200 chars)
"theme": "dark" | "light", // Color scheme
"template": string, // Template ID (default, vibrant, etc.)
"author_name": string, // Author display name
"author_avatar": string // URL to avatar image
}
Language Examples
cURL
curl -X POST https://ogimageapi.io/api/generate \
-H "Content-Type: application/json" \
-H "X-API-Key: your_api_key" \
-d '{"title": "Hello World", "theme": "dark"}' \
--output image.png
JavaScript / Node.js
const response = await fetch('https://ogimageapi.io/api/generate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'your_api_key'
},
body: JSON.stringify({
title: 'Hello World',
subtitle: 'Generated via API',
theme: 'dark'
})
});
const imageBuffer = await response.arrayBuffer();
Python
import requests
response = requests.post(
'https://ogimageapi.io/api/generate',
json={
'title': 'Hello World',
'subtitle': 'Generated via API',
'theme': 'dark'
},
headers={
'X-API-Key': 'your_api_key'
}
)
with open('image.png', 'wb') as f:
f.write(response.content)
PHP
$response = file_get_contents('https://ogimageapi.io/api/generate', false, stream_context_create([
'http' => [
'method' => 'POST',
'header' => "Content-Type: application/json\r\nX-API-Key: your_api_key",
'content' => json_encode([
'title' => 'Hello World',
'theme' => 'dark'
])
]
]));
file_put_contents('image.png', $response);
Response Codes
- 200 OK — Image generated successfully (returns PNG)
- 400 Bad Request — Invalid JSON or missing required fields
- 401 Unauthorized — Missing or invalid API key
- 429 Too Many Requests — Rate limit exceeded
- 500 Internal Server Error — Server-side error
Image Output
- Format: PNG
- Dimensions: 1200 × 630 pixels
- Color depth: 24-bit RGB
- Typical size: 30-80 KB
Start Generating Images from JSON
Get your API key and start making requests in minutes.
Get Your API Key →