Code Examples
Copy-paste examples for common use cases. Every example works with the free tier.
YouTube Thumbnail (Faceless)
cURL
curl -X POST https://api.thumbapi.dev/v1/generate \
-H "Authorization: Bearer $THUMBAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"title": "10 Tips to Grow Your YouTube Channel",
"format": "youtube",
"imageStyle": "faceless"
}'
JavaScript
const res = await fetch("https://api.thumbapi.dev/v1/generate", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.THUMBAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
title: "10 Tips to Grow Your YouTube Channel",
format: "youtube",
imageStyle: "faceless",
}),
});
const { image, format, dimensions } = await res.json();
Python
import requests, os
res = requests.post(
"https://api.thumbapi.dev/v1/generate",
headers={"Authorization": f"Bearer {os.environ['THUMBAPI_KEY']}"},
json={
"title": "10 Tips to Grow Your YouTube Channel",
"format": "youtube",
"imageStyle": "faceless",
},
)
data = res.json()
OG Image (Blog Post)
curl -X POST https://api.thumbapi.dev/v1/generate \
-H "Authorization: Bearer $THUMBAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"title": "Understanding Vector Databases: A Practical Guide",
"format": "blogpost",
"imageStyle": "faceless"
}'
Returns a 1200x630 image — the standard OG image size.
Instagram Post
curl -X POST https://api.thumbapi.dev/v1/generate \
-H "Authorization: Bearer $THUMBAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"title": "5 Morning Habits That Changed My Life",
"format": "instagram",
"imageStyle": "faceless"
}'
Returns a 1080x1080 square image.
With Person's Image
import { readFileSync } from "fs";
const personImage = readFileSync("./photo.jpg", "base64");
const res = await fetch("https://api.thumbapi.dev/v1/generate", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.THUMBAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
title: "My Journey to 1M Subscribers",
format: "youtube",
imageStyle: "with-image",
personImage: `data:image/jpeg;base64,${personImage}`,
}),
});
Save to Disk
Node.js
import { writeFileSync } from "fs";
const { image } = await res.json();
const base64 = image.replace(/^data:image\/webp;base64,/, "");
writeFileSync("thumbnail.webp", base64, "base64");
Python
import base64
b64 = data["image"].split(",")[1]
with open("thumbnail.webp", "wb") as f:
f.write(base64.b64decode(b64))
Error Handling
const res = await fetch("https://api.thumbapi.dev/v1/generate", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.THUMBAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify(requestBody),
});
if (!res.ok) {
const { error } = await res.json();
if (res.status === 429) {
// Rate limited — retry with backoff
} else if (res.status === 401) {
// Auth error — check API key
} else {
throw new Error(`ThumbAPI error ${res.status}: ${error}`);
}
}
Next Steps
- Endpoint reference — all parameters explained
- SDKs — official libraries with built-in retry
- Webhooks — async generation for pipelines