RendShot

JavaScript SDK — HTML to Image in Node.js

Install and use @rendshot/sdk to convert HTML to images in Node.js. Render HTML to PNG, JPEG, or WebP with TypeScript support.

The official Node.js / browser SDK for RendShot. Render HTML to images and capture URL screenshots with a typed, promise-based client.

Installation

terminal
npm install @rendshot/sdk

Setup

Create a client with your API key. The baseUrl defaults to https://api.rendshot.ai.

setup.ts
import { RendshotClient } from '@rendshot/sdk'

const client = new RendshotClient({
  apiKey: 'rs_live_YOUR_KEY',
  baseUrl: 'https://api.rendshot.ai', // optional
})

Render Image

Convert HTML/CSS to a PNG or JPEG image.

render.ts
const result = await client.renderImage({
  html: '<div style="padding:40px;background:#1a1a2e;color:#fff"><h1>Hello</h1></div>',
  css: 'h1 { font-size: 48px; }',
  width: 1200,
  height: 630,
  format: 'png',
  quality: 90,
  deviceScale: 2,
  fonts: ['Inter'],
  timeout: 10000,
})

console.log(result.imageId) // image id
console.log(result.url)     // https://assets.rendshot.ai/...

Options

Provide either html or template_id, not both.

NameTypeRequiredDescription
htmlstringYes*HTML content to render
template_idstringYes*Template ID (e.g. tpl_abc123)
variablesobjectNoTemplate variables as key-value pairs
cssstringNoAdditional CSS stylesheet
widthnumberNoViewport width, 1--4096
heightnumberNoViewport height, 1--4096
format'png' | 'jpg'NoOutput image format
qualitynumberNoImage quality, 1--100
deviceScale1 | 2 | 3NoDevice pixel ratio
fontsstring[]NoGoogle Fonts to load, e.g. ["Inter"]
timeoutnumberNoRender timeout in ms, 1000--30000

* Provide html for raw HTML rendering, or template_id for template-based rendering.

Render from Template

Use a published template with variable substitution. Browse templates with listTemplates(), inspect variables with getTemplate().

template-render.ts
// 1. Discover available templates
const { templates } = await client.listTemplates({ limit: 10 })

// 2. Inspect a template's variables
const template = await client.getTemplate('tpl_abc123')
console.log(template.name)      // "Social Card"
console.log(template.variables)  // [{ key: 'title', type: 'text', ... }]

// 3. Render with variables
const result = await client.renderImage({
  template_id: 'tpl_abc123',
  variables: {
    title: 'Hello World',
    bgColor: '#6B8F5E',
  },
})

console.log(result.url)

Template Methods

listTemplates(options?)

Browse published templates with optional filters.

OptionTypeDescription
platformstringFilter by platform (e.g. 'twitter', 'instagram')
categorystringFilter by category
qstringSearch by name or description
limitnumberMax results, 1--50 (default 20)
cursorstringPagination cursor from previous response

Returns { templates: TemplateInfo[], nextCursor: string | null }.

getTemplate(templateId)

Get a template's details including its variable definitions.

Returns a TemplateInfo object with id, name, description, width, height, variables, and more.

AI Render

Turn a natural-language prompt into a rendered image. See the AI Render guide for the full story.

ai-render.ts
const result = await client.aiRender({
  prompt: 'Social card announcing a product launch, minimal layout',
  platform: 'twitter_card',   // optional preset
  templateId: 'tpl_abc123',   // optional: use existing template as style reference
  width: 1200,
  height: 630,
  format: 'png',
  locale: 'en',                // 'zh' | 'en'
})

console.log(result.url)        // rendered image URL
console.log(result.html)       // AI-generated template HTML with {{placeholders}}
console.log(result.variables)  // AI-generated variable definitions

aiRender(options) Options

NameTypeRequiredDescription
promptstringYesNatural language description, 1--2000 chars
platformstringNoPreset (xiaohongshu, twitter_card, og_image, …) — sets default dimensions
templateIdstringNoExisting template ID to use as a visual style reference
widthnumberNoOverride preset width, 1--4096
heightnumberNoOverride preset height, 1--4096
format'png' | 'jpg'NoOutput image format
qualitynumberNoImage quality, 1--100
deviceScale1 | 2 | 3NoDevice pixel ratio
fontsstring[]NoGoogle Fonts to load
locale'zh' | 'en'NoLanguage of AI-generated text
timeoutnumberNoAI + render timeout, 1000--55000 ms

Each aiRender call counts as one request against your monthly quota — same as renderImage.

Saving the Result as a Template

Every aiRender response includes the raw html and variables, so you can round-trip it into a reusable template via createTemplate():

save-as-template.ts
const result = await client.aiRender({
  prompt: 'Minimal weekly digest cover',
  platform: 'xiaohongshu',
})

const tpl = await client.createTemplate({
  name: 'Weekly Digest',
  html: result.html,
  variables: result.variables,
  platform: 'xiaohongshu',
  width: result.width,
  height: result.height,
  // visibility defaults to 'private'
})

console.log(tpl.id)  // "tpl_xyz789" — use this for fast, deterministic re-renders

Create Template

Create a new private draft template. Does not consume render quota.

create-template.ts
const tpl = await client.createTemplate({
  name: 'Launch Card',
  html: '<div class="card"><h1>{{title}}</h1></div>',
  variables: [
    { key: 'title', type: 'text', label: 'Title', default: 'Hello' },
  ],
  platform: 'twitter_card',
  description: 'Marketing launch card',
  tags: ['marketing', 'launch'],
  // visibility: 'private' by default — publish from the web dashboard
})

console.log(tpl.id)           // "tpl_abc123"
console.log(tpl.status)       // "draft"
console.log(tpl.visibility)   // "private"

createTemplate(options) Options

NameTypeRequiredDescription
namestringYesTemplate name, 1--100 chars
htmlstringYesHTML with {{variable}} placeholders, up to 100 KB
variablesTemplateVariable[]YesVariable definitions (max 50)
descriptionstringNoHuman description
platformstringNoPlatform preset (defaults to custom)
categorystringNoCategory slug
tagsstring[]NoUp to 10 tags
widthnumberNoOverride preset width
heightnumberNoOverride preset height
cssstringNoExtra CSS, up to 100 KB
fontsstring[]NoGoogle Fonts to load
visibility'public' | 'private'NoDefaults to 'private'

Templates are always created with status: 'draft'. Publishing is a manual action in the web dashboard — a safety default so automated scripts cannot pollute the public gallery.

Screenshot URL

Capture a screenshot of any public URL.

screenshot.ts
const result = await client.screenshotUrl({
  url: 'https://example.com',
  width: 1280,
  height: 800,
  format: 'png',
  quality: 90,
  fullPage: false,
  deviceScale: 2,
  timeout: 15000,
})

console.log(result.url)

Options

NameTypeRequiredDescription
urlstringYesURL to screenshot
widthnumberNoViewport width, 1--4096
heightnumberNoViewport height, 1--4096
format'png' | 'jpg'NoOutput image format
qualitynumberNoImage quality, 1--100
fullPagebooleanNoCapture the full scrollable page
deviceScale1 | 2 | 3NoDevice pixel ratio
timeoutnumberNoRender timeout in ms, 1000--30000

Get Usage

Check your current billing period usage and plan limits.

usage.ts
const usage = await client.getUsage()

console.log(usage.plan)  // "free" | "pro"
console.log(usage.month) // "2026-03"
console.log(usage.count) // 42
console.log(usage.limit) // 100

Get Image Metadata

Retrieve metadata for a previously rendered image, including its expiration date.

metadata.ts
const image = await client.getImage('img_abc123')

console.log(image.id)        // "img_abc123"
console.log(image.url)       // "https://assets.rendshot.ai/..."
console.log(image.expiresAt) // "2027-04-22T00:00:00Z"

Error Handling

All API errors are thrown as RendshotError instances with structured .code, .status, and .message properties.

errors.ts
import { RendshotClient, RendshotError } from '@rendshot/sdk'

const client = new RendshotClient({ apiKey: 'rs_live_YOUR_KEY' })

try {
  await client.renderImage({ html: '<h1>Hello</h1>' })
} catch (err) {
  if (err instanceof RendshotError) {
    console.error(err.code)    // e.g. "RATE_LIMIT_EXCEEDED"
    console.error(err.status)  // e.g. 429
    console.error(err.message) // e.g. "Rate limit exceeded"
  }
}

TypeScript Exports

The SDK exports the following classes and types:

ExportKindDescription
RendshotClientclassMain API client
RendshotErrorclassStructured API error
RendshotClientConfigtypeClient constructor options
RenderImageOptionstypeOptions for renderImage() (union of RenderHtmlOptions | RenderTemplateOptions)
RenderHtmlOptionstypeHTML rendering options
RenderTemplateOptionstypeTemplate rendering options
ScreenshotUrlOptionstypeOptions for screenshotUrl()
ImageResulttypeRender/screenshot return value
ImageMetadatatypegetImage() return value with expiresAt
UsageResulttypegetUsage() return value
TemplateInfotypeTemplate metadata with variables
TemplateVariabletypeVariable definition (key, type, default, etc.)
TemplateListResulttypelistTemplates() return value
ListTemplatesOptionstypeOptions for listTemplates()
AiRenderOptionstypeOptions for aiRender()
AiRenderResulttypeaiRender() return value (image metadata + html + variables)
CreateTemplateOptionstypeOptions for createTemplate()
CreatedTemplatetypecreateTemplate() return value

Next Steps

On this page