Templates API - Browse & Create Templates
The Templates API lets you browse built-in templates, create custom templates for immediate use, and retrieve template details including schemas.
Endpoints Overview
Section titled “Endpoints Overview”| Method | Endpoint | Description |
|---|---|---|
GET | /v1/templates | List all built-in templates |
POST | /v1/templates | Create a custom template (24h TTL) |
GET | /v1/templates/:id | Get template details and schema |
GET | /v1/templates/:id/schema | Get template JSON schema only |
GET | /v1/templates/:id/preview | Get PNG thumbnail preview |
POST | /v1/templates/:id/validate | Validate data against template schema |
GET /v1/templates
Section titled “GET /v1/templates”GET /v1/templates
List all available built-in templates with metadata and sample data.
Request
Section titled “Request”Headers
Section titled “Headers”| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer gk_your_api_key |
Query Parameters
Section titled “Query Parameters”| Parameter | Type | Description |
|---|---|---|
category | string | Filter by category: quote, invoice, receipt, report, letter, contract, certificate, proposal, shipping, resume, menu, event, packing, purchase-order |
search | string | Search in template name and description |
style | string | Filter by style: modern, traditional, minimal, elegant |
tag | string | Filter by tag: modern, minimal, clean, bold, formal, ats-friendly, etc. |
Response
Section titled “Response”{ "templates": [ { "id": "invoice-clean", "name": "Clean Invoice", "description": "Clear, structured invoice with line items, totals, and payment terms.", "category": "invoice", "style": "modern", "tags": ["modern", "clean", "minimal"], "sampleData": { "invoice": { "number": "INV-2024-0042", "date": "January 20, 2024" }, "billTo": { "name": "Sarah Chen", "company": "Northwind Traders" }, "lineItems": [ { "description": "Brand Identity Package", "quantity": 1, "rate": "4,500.00", "amount": "4,500.00" } ], "totals": { "subtotal": "4,500.00", "total": "4,500.00" } } } ], "count": 15}Fields
Section titled “Fields”| Field | Type | Description |
|---|---|---|
templates | array | Array of template objects |
templates[].id | string | Template ID (use with /v1/create) |
templates[].name | string | Human-readable name |
templates[].description | string | Template description |
templates[].category | string | Document category |
templates[].style | string | Visual style preset |
templates[].tags | array | Searchable tags |
templates[].sampleData | object | Example data for the template |
count | number | Number of templates returned |
Code Examples
Section titled “Code Examples”# List all templatescurl https://api.glyph.you/v1/templates \ -H "Authorization: Bearer gk_your_api_key"
# Filter by categorycurl "https://api.glyph.you/v1/templates?category=invoice" \ -H "Authorization: Bearer gk_your_api_key"
# Search templatescurl "https://api.glyph.you/v1/templates?search=professional" \ -H "Authorization: Bearer gk_your_api_key"
# Filter by style and tagcurl "https://api.glyph.you/v1/templates?style=modern&tag=minimal" \ -H "Authorization: Bearer gk_your_api_key"JavaScript
Section titled “JavaScript”const response = await fetch('https://api.glyph.you/v1/templates?category=invoice', { headers: { 'Authorization': 'Bearer gk_your_api_key' }});
const { templates, count } = await response.json();console.log(`Found ${count} invoice templates`);
for (const template of templates) { console.log(`- ${template.name} (${template.id})`); console.log(` Style: ${template.style}, Tags: ${template.tags.join(', ')}`);}Python
Section titled “Python”import requests
response = requests.get( 'https://api.glyph.you/v1/templates', params={'category': 'invoice'}, headers={'Authorization': 'Bearer gk_your_api_key'})
data = response.json()print(f"Found {data['count']} invoice templates")
for template in data['templates']: print(f"- {template['name']} ({template['id']})")POST /v1/templates
Section titled “POST /v1/templates”POST /v1/templates
Create a custom template for immediate use. The returned template ID (tpl_xxx) can be used with /v1/create to generate PDFs.
Request
Section titled “Request”Headers
Section titled “Headers”| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer gk_your_api_key |
Content-Type | Yes | application/json |
{ "name": "my-custom-invoice", "html": "<html><head><style>body { font-family: sans-serif; padding: 40px; }</style></head><body><h1>Invoice #{{invoice_number}}</h1><p>Client: {{client.name}}</p><p>Total: ${{total}}</p></body></html>", "schema": { "invoice_number": { "type": "string" }, "client": { "type": "object" }, "total": { "type": "number" } }, "description": "Custom invoice template for quick testing"}Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Template name (1-255 characters) |
html | string | Yes | Mustache HTML template |
schema | object | No | JSON schema defining expected data fields (default: {}) |
description | string | No | Human-readable description (max 1000 characters) |
Response (201 Created)
Section titled “Response (201 Created)”{ "success": true, "id": "tpl_a1b2c3d4", "name": "my-custom-invoice", "createdAt": "2026-01-28T12:00:00.000Z", "expiresAt": "2026-01-29T12:00:00.000Z", "usage": { "createEndpoint": "/v1/create", "example": { "templateId": "tpl_a1b2c3d4", "data": "{ ...your data matching the schema... }" } }, "_links": { "create": "/v1/create", "template": "/v1/templates/tpl_a1b2c3d4" }}Fields
Section titled “Fields”| Field | Type | Description |
|---|---|---|
success | boolean | Whether creation succeeded |
id | string | Template ID (format: tpl_xxx) for use with /v1/create |
name | string | Template name |
createdAt | string | ISO 8601 creation timestamp |
expiresAt | string | ISO 8601 expiration timestamp (24 hours from creation) |
usage | object | Usage instructions |
_links | object | Hypermedia links for next actions |
Code Examples
Section titled “Code Examples”curl -X POST https://api.glyph.you/v1/templates \ -H "Authorization: Bearer gk_your_api_key" \ -H "Content-Type: application/json" \ -d '{ "name": "quick-receipt", "html": "<html><head><style>body { font-family: monospace; padding: 20px; } .total { font-size: 24px; font-weight: bold; }</style></head><body><h1>Receipt</h1><p>Date: {{date}}</p><p>Item: {{item}}</p><p class=\"total\">Total: ${{amount}}</p><p>Thank you for your purchase!</p></body></html>", "schema": { "date": { "type": "string" }, "item": { "type": "string" }, "amount": { "type": "number" } }, "description": "Simple receipt for testing" }'JavaScript
Section titled “JavaScript”const response = await fetch('https://api.glyph.you/v1/templates', { method: 'POST', headers: { 'Authorization': 'Bearer gk_your_api_key', 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'quick-receipt', html: ` <html> <head> <style> body { font-family: monospace; padding: 20px; } .total { font-size: 24px; font-weight: bold; } </style> </head> <body> <h1>Receipt</h1> <p>Date: {{date}}</p> <p>Item: {{item}}</p> <p class="total">Total: \${{amount}}</p> <p>Thank you for your purchase!</p> </body> </html> `, schema: { date: { type: 'string' }, item: { type: 'string' }, amount: { type: 'number' } } })});
const result = await response.json();console.log(`Template created: ${result.id}`);console.log(`Expires: ${result.expiresAt}`);
// Now use it to generate a PDFconst pdfResponse = await fetch('https://api.glyph.you/v1/create', { method: 'POST', headers: { 'Authorization': 'Bearer gk_your_api_key', 'Content-Type': 'application/json' }, body: JSON.stringify({ templateId: result.id, data: { date: 'January 28, 2026', item: 'Premium Subscription', amount: 99.99 } })});Python
Section titled “Python”import requests
# Create the templateresponse = requests.post( 'https://api.glyph.you/v1/templates', headers={ 'Authorization': 'Bearer gk_your_api_key', 'Content-Type': 'application/json' }, json={ 'name': 'quick-receipt', 'html': ''' <html> <head> <style> body { font-family: monospace; padding: 20px; } .total { font-size: 24px; font-weight: bold; } </style> </head> <body> <h1>Receipt</h1> <p>Date: {{date}}</p> <p>Item: {{item}}</p> <p class="total">Total: ${{amount}}</p> <p>Thank you for your purchase!</p> </body> </html> ''', 'schema': { 'date': {'type': 'string'}, 'item': {'type': 'string'}, 'amount': {'type': 'number'} } })
result = response.json()template_id = result['id']print(f"Template created: {template_id}")print(f"Expires: {result['expiresAt']}")
# Use the template to generate a PDFpdf_response = requests.post( 'https://api.glyph.you/v1/create', headers={ 'Authorization': 'Bearer gk_your_api_key', 'Content-Type': 'application/json' }, json={ 'templateId': template_id, 'data': { 'date': 'January 28, 2026', 'item': 'Premium Subscription', 'amount': 99.99 } })GET /v1/templates/:id
Section titled “GET /v1/templates/:id”GET /v1/templates/:id
Get full template details including JSON schema and sample data. Works for both built-in templates and custom templates (IDs starting with tpl_).
Request
Section titled “Request”Headers
Section titled “Headers”| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer gk_your_api_key |
Path Parameters
Section titled “Path Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Template ID (e.g., invoice-clean or tpl_a1b2c3d4) |
Response (Built-in Template)
Section titled “Response (Built-in Template)”{ "id": "invoice-clean", "name": "Clean Invoice", "description": "Clear, structured invoice with line items, totals, and payment terms.", "type": "builtin", "schema": { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "properties": { "invoice": { "type": "object", "properties": { "number": { "type": "string" }, "date": { "type": "string" }, "dueDate": { "type": "string" } } }, "billTo": { "type": "object", "properties": { "name": { "type": "string" }, "company": { "type": "string" } } }, "lineItems": { "type": "array", "items": { "type": "object", "properties": { "description": { "type": "string" }, "quantity": { "type": "number" }, "rate": { "type": "string" }, "amount": { "type": "string" } } } } } }, "sampleData": { "invoice": { "number": "INV-2024-0042", "date": "January 20, 2024" }, "billTo": { "name": "Sarah Chen", "company": "Northwind Traders" }, "lineItems": [ { "description": "Brand Identity Package", "quantity": 1, "rate": "4,500.00", "amount": "4,500.00" } ] }}Response (Custom Template)
Section titled “Response (Custom Template)”{ "id": "tpl_a1b2c3d4", "name": "my-custom-invoice", "description": "Custom invoice template for quick testing", "type": "custom", "html": "<html>...</html>", "schema": { "invoice_number": { "type": "string" }, "client": { "type": "object" }, "total": { "type": "number" } }, "createdAt": "2026-01-28T12:00:00.000Z", "expiresAt": "2026-01-29T12:00:00.000Z"}Fields
Section titled “Fields”| Field | Type | Description |
|---|---|---|
id | string | Template ID |
name | string | Template name |
description | string | Template description |
type | string | builtin or custom |
schema | object | JSON schema for data validation |
sampleData | object | Example data (built-in templates only) |
html | string | Template HTML (custom templates only) |
createdAt | string | Creation timestamp (custom templates only) |
expiresAt | string | Expiration timestamp (custom templates only) |
Code Examples
Section titled “Code Examples”# Get a built-in templatecurl https://api.glyph.you/v1/templates/invoice-clean \ -H "Authorization: Bearer gk_your_api_key"
# Get a custom templatecurl https://api.glyph.you/v1/templates/tpl_a1b2c3d4 \ -H "Authorization: Bearer gk_your_api_key"JavaScript
Section titled “JavaScript”const templateId = 'invoice-clean';
const response = await fetch(`https://api.glyph.you/v1/templates/${templateId}`, { headers: { 'Authorization': 'Bearer gk_your_api_key' }});
const template = await response.json();console.log(`Template: ${template.name}`);console.log(`Type: ${template.type}`);console.log(`Schema fields: ${Object.keys(template.schema.properties || template.schema).join(', ')}`);Python
Section titled “Python”import requests
template_id = 'invoice-clean'
response = requests.get( f'https://api.glyph.you/v1/templates/{template_id}', headers={'Authorization': 'Bearer gk_your_api_key'})
template = response.json()print(f"Template: {template['name']}")print(f"Type: {template['type']}")
# Use sampleData to generate a PDF immediatelyif 'sampleData' in template: print("Sample data available for testing")GET /v1/templates/:id/schema
Section titled “GET /v1/templates/:id/schema”GET /v1/templates/:id/schema
Get only the JSON schema for a built-in template. Useful for AI agents and validation tools.
Request
Section titled “Request”Headers
Section titled “Headers”| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer gk_your_api_key |
Path Parameters
Section titled “Path Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Built-in template ID (e.g., invoice-clean) |
Response
Section titled “Response”Returns raw JSON Schema with Content-Type: application/schema+json.
{ "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "properties": { "invoice": { "type": "object", "properties": { "number": { "type": "string" }, "date": { "type": "string" } } }, "lineItems": { "type": "array", "items": { ... } } }, "required": ["invoice", "lineItems"]}Code Examples
Section titled “Code Examples”curl https://api.glyph.you/v1/templates/invoice-clean/schema \ -H "Authorization: Bearer gk_your_api_key"GET /v1/templates/:id/preview
Section titled “GET /v1/templates/:id/preview”GET /v1/templates/:id/preview
Get a PNG thumbnail preview of a built-in template rendered with sample data. Thumbnails are 400x300 pixels and cached for 24 hours.
Request
Section titled “Request”Headers
Section titled “Headers”| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer gk_your_api_key |
Path Parameters
Section titled “Path Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Built-in template ID (e.g., invoice-clean) |
Response
Section titled “Response”Returns PNG image data with Content-Type: image/png.
Code Examples
Section titled “Code Examples”curl https://api.glyph.you/v1/templates/invoice-clean/preview \ -H "Authorization: Bearer gk_your_api_key" \ --output preview.png<img src="https://api.glyph.you/v1/templates/invoice-clean/preview" alt="Invoice template preview" width="400" height="300"/>POST /v1/templates/:id/validate
Section titled “POST /v1/templates/:id/validate”POST /v1/templates/:id/validate
Validate your data against a template’s JSON schema before generating a PDF. Returns errors for missing required fields and type mismatches.
Request
Section titled “Request”Headers
Section titled “Headers”| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer gk_your_api_key |
Content-Type | Yes | application/json |
Path Parameters
Section titled “Path Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Template ID |
{ "data": { "invoice": { "number": "INV-001" }, "lineItems": [ { "description": "Consulting", "quantity": 1 } ] }}Response
Section titled “Response”{ "valid": true, "templateId": "invoice-clean", "errors": [], "warnings": [ { "field": "invoice.date", "message": "Optional field not provided" }, { "field": "invoice.dueDate", "message": "Optional field not provided" } ]}Fields
Section titled “Fields”| Field | Type | Description |
|---|---|---|
valid | boolean | Whether data passes validation (no errors) |
templateId | string | Template ID validated against |
errors | array | Required field or type errors |
warnings | array | Optional fields not provided |
Code Examples
Section titled “Code Examples”curl -X POST https://api.glyph.you/v1/templates/invoice-clean/validate \ -H "Authorization: Bearer gk_your_api_key" \ -H "Content-Type: application/json" \ -d '{ "data": { "invoice": { "number": "INV-001" }, "billTo": { "name": "John Doe" }, "lineItems": [ { "description": "Consulting", "quantity": 1, "rate": "150.00", "amount": "150.00" } ], "totals": { "subtotal": "150.00", "total": "150.00" } } }'JavaScript
Section titled “JavaScript”const data = { invoice: { number: 'INV-001' }, billTo: { name: 'John Doe' }, lineItems: [{ description: 'Consulting', quantity: 1 }]};
const response = await fetch('https://api.glyph.you/v1/templates/invoice-clean/validate', { method: 'POST', headers: { 'Authorization': 'Bearer gk_your_api_key', 'Content-Type': 'application/json' }, body: JSON.stringify({ data })});
const result = await response.json();
if (result.valid) { console.log('Data is valid, proceeding with PDF generation');} else { console.log('Validation errors:', result.errors);}Available Built-in Templates
Section titled “Available Built-in Templates”| ID | Name | Category | Description |
|---|---|---|---|
quote-modern | Modern Quote | quote | Clean, minimal quote with sans-serif fonts |
quote-bold | Bold Quote | quote | High-impact modern design |
quote-professional | Professional Quote | quote | Traditional business style |
invoice-clean | Clean Invoice | invoice | Structured invoice with line items |
receipt-minimal | Minimal Receipt | receipt | Compact receipt layout |
report-cover | Report Cover Page | report | Professional cover page |
contract-simple | Simple Contract | contract | Clean service agreement |
certificate-modern | Modern Certificate | certificate | Elegant certificate of achievement |
letter-business | Business Letter | letter | Professional business letter |
proposal-basic | Basic Proposal | proposal | Project proposal with timeline |
shipping-label | Shipping Label | shipping | Standard 4x6 shipping label |
resume | Professional Resume | resume | ATS-friendly resume template |
menu | Restaurant Menu | menu | Elegant restaurant menu |
event-ticket | Event Ticket | event | Concert/event ticket with barcode |
packing-slip | Packing Slip | packing | Warehouse packing slip |
purchase-order | Purchase Order | purchase-order | Formal procurement document |
Error Responses
Section titled “Error Responses”400 - Validation Error
Section titled “400 - Validation Error”{ "error": "Validation failed", "code": "VALIDATION_ERROR", "details": [ { "path": ["name"], "message": "Template name is required" } ]}404 - Template Not Found
Section titled “404 - Template Not Found”{ "error": "Template 'invalid-id' not found", "code": "TEMPLATE_NOT_FOUND"}404 - Custom Template Expired
Section titled “404 - Custom Template Expired”{ "error": "Template not found or expired", "code": "TEMPLATE_NOT_FOUND"}500 - Template Creation Error
Section titled “500 - Template Creation Error”{ "error": "Failed to create template", "code": "TEMPLATE_CREATION_ERROR"}See Also
Section titled “See Also”- POST /v1/create - Generate PDFs using templates
- Custom Templates API - Permanent template storage
- Templates Overview - Visual template gallery
- Batch Generation - Generate multiple PDFs from templates