Skip to content

POST /v1/generate

POST /v1/generate

Generates a PDF or PNG file from HTML content. This endpoint uses Playwright to render the document with full CSS support.

HeaderRequiredDescription
AuthorizationYesBearer gk_your_api_key
Content-TypeYesapplication/json
AcceptNoapplication/json for metadata, omit for raw file
{
"html": "<!DOCTYPE html><html>...</html>",
"format": "pdf",
"options": {
"width": 816,
"height": 1056,
"scale": 1
}
}
ParameterTypeRequiredDescription
htmlstringYesHTML content to render
formatstringYesOutput format: "pdf" or "png"
optionsobjectNoRendering options
options.widthnumberNoPage width in pixels (default: 816 = 8.5in @ 96dpi)
options.heightnumberNoPage height in pixels (default: 1056 = 11in @ 96dpi)
options.scalenumberNoScale factor (0.1 to 3, default: 1)

When no Accept: application/json header is provided, the response is the raw file:

Headers:

Content-Type: application/pdf
Content-Disposition: attachment; filename="document-1705320000000.pdf"
Content-Length: 45678

Body: Binary PDF/PNG data

When Accept: application/json is provided:

{
"url": "data:application/pdf;base64,JVBERi0xLjQK...",
"format": "pdf",
"size": 45678,
"expiresAt": "2024-01-16T12:00:00.000Z"
}
FieldTypeDescription
urlstringBase64 data URL of the generated file
formatstringOutput format (pdf or png)
sizenumberFile size in bytes
expiresAtstringExpiration timestamp (24 hours)

400 Bad Request - Invalid parameters

{
"error": "Validation failed",
"code": "VALIDATION_ERROR",
"details": [
{
"path": ["format"],
"message": "Invalid enum value. Expected 'pdf' | 'png'"
}
]
}

429 Too Many Requests - Monthly limit exceeded

{
"error": "Monthly PDF limit exceeded",
"code": "MONTHLY_LIMIT_EXCEEDED",
"limit": 100,
"used": 100,
"tier": "free",
"upgrade": "https://glyph.you/pricing"
}

503 Service Unavailable - Playwright not available

{
"error": "PDF generation not available. Playwright is not installed.",
"code": "PLAYWRIGHT_NOT_INSTALLED",
"details": {
"install": "bun add playwright && npx playwright install chromium"
}
}
Terminal window
curl -X POST https://api.glyph.you/v1/generate \
-H "Authorization: Bearer gk_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"html": "<!DOCTYPE html><html><body><h1>Hello World</h1></body></html>",
"format": "pdf"
}' \
--output document.pdf
Terminal window
curl -X POST https://api.glyph.you/v1/generate \
-H "Authorization: Bearer gk_your_api_key" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"html": "<!DOCTYPE html><html><body><h1>Hello World</h1></body></html>",
"format": "pdf"
}'
const response = await fetch('https://api.glyph.you/v1/generate', {
method: 'POST',
headers: {
'Authorization': 'Bearer gk_your_api_key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
html: document.querySelector('glyph-editor').getHtml(),
format: 'pdf'
})
});
// Create download link
const blob = await response.blob();
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'quote.pdf';
a.click();
URL.revokeObjectURL(url);
import { writeFileSync } from 'fs';
const response = await fetch('https://api.glyph.you/v1/generate', {
method: 'POST',
headers: {
'Authorization': 'Bearer gk_your_api_key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
html: htmlContent,
format: 'pdf'
})
});
const buffer = Buffer.from(await response.arrayBuffer());
writeFileSync('document.pdf', buffer);
import requests
response = requests.post(
'https://api.glyph.you/v1/generate',
headers={
'Authorization': 'Bearer gk_your_api_key',
'Content-Type': 'application/json'
},
json={
'html': html_content,
'format': 'pdf'
}
)
# Save to file
with open('document.pdf', 'wb') as f:
f.write(response.content)

Common page sizes in pixels (at 96 DPI):

SizeWidthHeight
Letter (8.5” x 11”)8161056
A4 (210mm x 297mm)7941123
Legal (8.5” x 14”)8161344
Tabloid (11” x 17”)10561632
{
"html": "...",
"format": "pdf",
"options": {
"width": 794,
"height": 1123
}
}

For image output:

{
"html": "...",
"format": "png",
"options": {
"scale": 2
}
}
  1. Use session-based workflow - Generate from a session to ensure you have the latest modifications
  2. Handle large files - PDFs can be several MB; use streaming for large documents
  3. Cache when possible - Store generated PDFs to avoid regenerating unchanged documents
  4. Monitor usage - Check your monthly limit headers to avoid interruptions