Generate Alt Text API Documentation
Why Use the Generate Alt Text API?
This API helps blogs and e-commerce websites improve their SEO by generating optimized alt text for images. Well-crafted alt texts are essential for increasing visibility in search engines, driving traffic, and improving conversions. E-commerce websites can see better user engagement as search engines identify and rank the images better, increasing accessibility and offering users a better experience.
Technical Details
The API is located at https://clusterify.ai/api/generate-alt-text
and is accessed via a POST request.
Request Parameters
Parameter | Type | Required | Description |
---|---|---|---|
keyword | string | Yes | The primary keyword to optimize the alt text (10-50 characters). |
subject | string | Yes | A brief subject description of the image (5-50 characters). |
filename | string | No | Optional. The desired filename (5-50 characters, without extension). |
Response
The API returns a JSON array with recommendations for alt text and file names, sorted by SEO score (highest to lowest). You should select the first recommendation, as it has the best SEO score.
[
{
"score": 10,
"alt": "SEO-optimized alt text 1",
"filename": "recommended-filename-1",
"explanation": "Explanation of why this alt text was chosen."
},
{
"score": 9,
"alt": "SEO-optimized alt text 2",
"filename": "recommended-filename-2",
"explanation": "Explanation of why this alt text was chosen."
},
// Three more entries...
]
Authentication
You need to authenticate via JWT. First, use the login API to get your token. Here’s how to do it with CURL:
curl -X POST https://clusterify.ai/api/login \
-H "Content-Type: application/json" \
-d '{"public_key": "your_public_key", "secret_key": "your_secret_key"}'
This returns a JWT token that you can use for the API call.
Example API Call Using CURL
curl -X POST https://clusterify.ai/api/generate-alt-text \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your_token" \
-d '{
"keyword": "vintage sneakers",
"subject": "a pair of classic white sneakers",
"filename": "white-classic-sneakers"
}'
Example API Call Using Python
import requests
url = "https://clusterify.ai/api/generate-alt-text"
headers = {
"Authorization": "Bearer your_token",
"Content-Type": "application/json"
}
data = {
"keyword": "vintage sneakers",
"subject": "a pair of classic white sneakers",
"filename": "white-classic-sneakers" # Optional
}
response = requests.post(url, json=data, headers=headers)
print(response.json())
Example API Call Using Next.js (Fetch)
async function generateAltText() {
const res = await fetch('https://clusterify.ai/api/generate-alt-text', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer your_token',
},
body: JSON.stringify({
keyword: 'vintage sneakers',
subject: 'a pair of classic white sneakers',
filename: 'white-classic-sneakers' // Optional
}),
});
const data = await res.json();
console.log(data);
}
Example API Call Using PHP
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://clusterify.ai/api/generate-alt-text");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: Bearer your_token",
"Content-Type: application/json"
));
$data = json_encode([
"keyword" => "vintage sneakers",
"subject" => "a pair of classic white sneakers",
"filename" => "white-classic-sneakers" // Optional
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>