Documentation
Authentication
HTML to Image uses API keys to authenticate requests. You can obtain your API key from the dashboard.
All API requests must include your API key in the X-API-Key
header.
Example Requests
cURL
# HTML/CSS API
curl -X POST 'https://app.html2img.com/api/html' \
-H 'X-API-Key: your_api_key' \
-H 'Content-Type: application/json' \
-d '{
"html": "<h1>Hello World</h1>",
"css": "h1 { color: blue; }"
}'
# Screenshot API
curl -X POST 'https://app.html2img.com/api/screenshot' \
-H 'X-API-Key: your_api_key' \
-H 'Content-Type: application/json' \
-d '{
"url": "https://example.com",
"width": 1920,
"height": 1080
}'
Python
import requests
# HTML/CSS API
response = requests.post(
'https://app.html2img.com/api/html',
headers={
'X-API-Key': 'your_api_key'
},
json={
'html': '<h1>Hello World</h1>',
'css': 'h1 { color: blue; }'
}
)
# Screenshot API
response = requests.post(
'https://app.html2img.com/api/screenshot',
headers={
'X-API-Key': 'your_api_key'
},
json={
'url': 'https://example.com',
'width': 1920,
'height': 1080
}
)
Node.js
// Using fetch
const htmlResponse = await fetch('https://app.html2img.com/api/html', {
method: 'POST',
headers: {
'X-API-Key': 'your_api_key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
html: '<h1>Hello World</h1>',
css: 'h1 { color: blue; }'
})
});
const screenshotResponse = await fetch('https://app.html2img.com/api/screenshot', {
method: 'POST',
headers: {
'X-API-Key': 'your_api_key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
url: 'https://example.com',
width: 1920,
height: 1080
})
});
// Using axios
const axios = require('axios');
const htmlResponse = await axios.post('https://app.html2img.com/api/html', {
html: '<h1>Hello World</h1>',
css: 'h1 { color: blue; }'
}, {
headers: {
'X-API-Key': 'your_api_key'
}
});
const screenshotResponse = await axios.post('https://app.html2img.com/api/screenshot', {
url: 'https://example.com',
width: 1920,
height: 1080
}, {
headers: {
'X-API-Key': 'your_api_key'
}
});
PHP
// Using cURL
$ch = curl_init();
// HTML/CSS API
curl_setopt($ch, CURLOPT_URL, 'https://app.html2img.com/api/html');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-API-Key: your_api_key',
'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'html' => '<h1>Hello World</h1>',
'css' => 'h1 { color: blue; }'
]));
$response = curl_exec($ch);
// Screenshot API
curl_setopt($ch, CURLOPT_URL, 'https://app.html2img.com/api/screenshot');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'url' => 'https://example.com',
'width' => 1920,
'height' => 1080
]));
$response = curl_exec($ch);
curl_close($ch);
// Using Guzzle
use GuzzleHttp\Client;
$client = new Client();
$htmlResponse = $client->post('https://app.html2img.com/api/html', [
'headers' => [
'X-API-Key' => 'your_api_key'
],
'json' => [
'html' => '<h1>Hello World</h1>',
'css' => 'h1 { color: blue; }'
]
]);
$screenshotResponse = $client->post('https://app.html2img.com/api/screenshot', [
'headers' => [
'X-API-Key' => 'your_api_key'
],
'json' => [
'url' => 'https://example.com',
'width' => 1920,
'height' => 1080
]
]);