A template defines reusable image markup with variables that are replaced when an image is created.
You can create templates by sending HTML and CSS to the API, or by building a template visually in the Template Editor. Templates created in the editor are still rendered through the same template API.
If you are building templates visually, start with the Template Editor Quick Start. For API-only templates, continue below.
Handlebars variables
Templates support Handlebars variables. Add {{title_text}} to your HTML, then pass a value for title_text when creating the image.
Common use cases
Define a reusable template, then pass variables to it to generate unique images.
Use the Template Editor to build a reusable image from blocks instead of writing all of the HTML and CSS by hand.
Create images using signed URLs in a GET request.
Generate social sharing images, such as og:image or twitter:image. For an existing website or CMS, an OG Image Config can populate the template from each page’s metadata.
Example
This image was generated with a template.
{"text":"With templates, you can use variables to replace parts of your image.","avatar_url":"https://avataaars.io/?avatarStyle=Transparent&topType=ShortHairDreads01&accessoriesType=Round&hairColor=BrownDark&facialHairType=BeardLight&facialHairColor=BrownDark&clotheType=BlazerShirt&eyeType=Happy&eyebrowType=DefaultNatural&mouthType=Eating&skinColor=Brown","name":"Freddy","username":"@freddy",}
To generate a template, make an HTTP request to the API.
post https://hcti.io/v1/template
Parameters
The create template endpoint accepts the following parameters. Accepted as either json or formdata.
Name
Type
Description
html*
String
This is the HTML you want to render. You can send an HTML snippet (<div>Your content</div>) or an entire webpage.
css
String
The CSS for your image.
name
String
A short name to identify your template max length 64
description
String
Description to elaborate on the use of your template max length 1024
Required params
For creating a template, html is required while css is optional. name and description are optional, but may be useful to help you differentiate your templates in the future.
Additional parameters
Optional parameters for greater control over your image.
{"error":"Bad Request","statusCode":400,"message":"HTML is Required"}
STATUS: 429 TOO MANY REQUESTS
{"error":"Plan limit exceeded","statusCode":429,"message":"The tryit plan is limited to 1 template"}
Plan Limits
Free plans can create 1 template. Paid plans can create 1,000. You can edit your existing templates an unlimited number of times.
Editing a Template
To edit a template you’ve already made, make an HTTP request to the API with the template_id listed in the CREATE response.
post https://hcti.io/v1/template/:template_id
Parameters
The edit template endpoint accepts the following parameters. Accepted as either json or formdata.
Name
Type
Description
html*
String
This is the HTML you want to render. You can send an HTML snippet (<div>Your content</div>) or an entire webpage.
css
String
The CSS for your image.
name
String
A short name to identify your template max length 64
description
String
Description to elaborate on the use of your template max length 1024
Required params
For creating a template, html is required while css is optional. name and description are optional, but may be useful to help you differentiate your templates in the future.
Additional parameters
Optional parameters for greater control over your image.
Set the width of Chrome’s viewport. Both dimensions must be set when using either.
Creating an image with a template
To generate a templated image, make an HTTP request to the API using the template_id listed in the CREATE response.
post https://hcti.io/v1/image/:template_id
You can also generate a templated image with a signed GET URL that renders on demand. See Creating a templated image URL.
To use one template for automatic social cards across an existing site, select it in an OG Image Config. HCTI can map page titles, descriptions, Open Graph metadata, and explicit html:tv: values to its variables.
Template Versions
When you create an image using a template_id, it will automatically use the most recent version of that template. If you want to create an image from a specific template_version you can append /:template_version to your POST: hcti.io/v1/image/:template_id/:template_version
Parameters
The create templated image endpoint accepts the following parameters, accepted as either json or formdata.
If you use formdata, your template_values need to be JSON encoded.
Name
Type
Description
template_values*
JSON
Values for the variables in your template. For editor templates, see the Variables guide.
Listing your templates
To list all of your templates, send a get to v1/template. Authentication is required.