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
npm install @rendshot/sdkSetup
Create a client with your API key. The baseUrl defaults to https://api.rendshot.ai.
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.
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.
| Name | Type | Required | Description |
|---|---|---|---|
html | string | Yes* | HTML content to render |
template_id | string | Yes* | Template ID (e.g. tpl_abc123) |
variables | object | No | Template variables as key-value pairs |
css | string | No | Additional CSS stylesheet |
width | number | No | Viewport width, 1--4096 |
height | number | No | Viewport height, 1--4096 |
format | 'png' | 'jpg' | No | Output image format |
quality | number | No | Image quality, 1--100 |
deviceScale | 1 | 2 | 3 | No | Device pixel ratio |
fonts | string[] | No | Google Fonts to load, e.g. ["Inter"] |
timeout | number | No | Render 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().
// 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.
| Option | Type | Description |
|---|---|---|
platform | string | Filter by platform (e.g. 'twitter', 'instagram') |
category | string | Filter by category |
q | string | Search by name or description |
limit | number | Max results, 1--50 (default 20) |
cursor | string | Pagination 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.
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 definitionsaiRender(options) Options
| Name | Type | Required | Description |
|---|---|---|---|
prompt | string | Yes | Natural language description, 1--2000 chars |
platform | string | No | Preset (xiaohongshu, twitter_card, og_image, …) — sets default dimensions |
templateId | string | No | Existing template ID to use as a visual style reference |
width | number | No | Override preset width, 1--4096 |
height | number | No | Override preset height, 1--4096 |
format | 'png' | 'jpg' | No | Output image format |
quality | number | No | Image quality, 1--100 |
deviceScale | 1 | 2 | 3 | No | Device pixel ratio |
fonts | string[] | No | Google Fonts to load |
locale | 'zh' | 'en' | No | Language of AI-generated text |
timeout | number | No | AI + 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():
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-rendersCreate Template
Create a new private draft template. Does not consume render quota.
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
| Name | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Template name, 1--100 chars |
html | string | Yes | HTML with {{variable}} placeholders, up to 100 KB |
variables | TemplateVariable[] | Yes | Variable definitions (max 50) |
description | string | No | Human description |
platform | string | No | Platform preset (defaults to custom) |
category | string | No | Category slug |
tags | string[] | No | Up to 10 tags |
width | number | No | Override preset width |
height | number | No | Override preset height |
css | string | No | Extra CSS, up to 100 KB |
fonts | string[] | No | Google Fonts to load |
visibility | 'public' | 'private' | No | Defaults 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.
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
| Name | Type | Required | Description |
|---|---|---|---|
url | string | Yes | URL to screenshot |
width | number | No | Viewport width, 1--4096 |
height | number | No | Viewport height, 1--4096 |
format | 'png' | 'jpg' | No | Output image format |
quality | number | No | Image quality, 1--100 |
fullPage | boolean | No | Capture the full scrollable page |
deviceScale | 1 | 2 | 3 | No | Device pixel ratio |
timeout | number | No | Render timeout in ms, 1000--30000 |
Get Usage
Check your current billing period usage and plan limits.
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) // 100Get Image Metadata
Retrieve metadata for a previously rendered image, including its expiration date.
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.
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:
| Export | Kind | Description |
|---|---|---|
RendshotClient | class | Main API client |
RendshotError | class | Structured API error |
RendshotClientConfig | type | Client constructor options |
RenderImageOptions | type | Options for renderImage() (union of RenderHtmlOptions | RenderTemplateOptions) |
RenderHtmlOptions | type | HTML rendering options |
RenderTemplateOptions | type | Template rendering options |
ScreenshotUrlOptions | type | Options for screenshotUrl() |
ImageResult | type | Render/screenshot return value |
ImageMetadata | type | getImage() return value with expiresAt |
UsageResult | type | getUsage() return value |
TemplateInfo | type | Template metadata with variables |
TemplateVariable | type | Variable definition (key, type, default, etc.) |
TemplateListResult | type | listTemplates() return value |
ListTemplatesOptions | type | Options for listTemplates() |
AiRenderOptions | type | Options for aiRender() |
AiRenderResult | type | aiRender() return value (image metadata + html + variables) |
CreateTemplateOptions | type | Options for createTemplate() |
CreatedTemplate | type | createTemplate() return value |
Next Steps
- Python SDK -- Official Python client
- CLI -- Use RendShot from the command line
- MCP Server -- Integrate with Claude and AI assistants
- API Reference -- Full endpoint documentation