Your First Render
You need three things from the previous steps:
- your secret key (
sk_live_…) in aREFORGIO_SECRET_KEYenv var, - the ID of a published template (open the template in the dashboard — the ID is in the URL),
@reforgio/sdk-coreinstalled.
Render from Node.js
first-render.ts
import { ReforgioServer, ReforgioError } from '@reforgio/sdk-core/server'
const reforgio = new ReforgioServer(process.env.REFORGIO_SECRET_KEY!)
async function main(): Promise<void> {
try {
const doc = await reforgio.render('YOUR_TEMPLATE_ID', {
invoice_number: 'INV-2026-001',
customer_name: 'ACME Corp',
items: [{ name: 'Design work', quantity: 10, price: 120 }],
})
console.log(`Rendered in ${doc.renderTimeMs}ms (${doc.fileSizeBytes} bytes)`)
console.log(`Download: ${doc.downloadUrl}`)
} catch (err) {
if (err instanceof ReforgioError) {
// API errors carry the HTTP status and the server's message
console.error(`Render failed (${err.statusCode}): ${err.message}`)
process.exitCode = 1
return
}
throw err // network/unexpected errors
}
}
void main()Replace YOUR_TEMPLATE_ID and the data keys with your template’s actual variables, then:
REFORGIO_SECRET_KEY=sk_live_... npx tsx first-render.tsA successful render responds with:
{
"documentId": "cm1a2b3c4d",
"status": "completed",
"downloadUrl": "https://…presigned storage URL…",
"fileSizeBytes": 54321,
"renderTimeMs": 320
}Open downloadUrl in a browser — that’s your PDF. Pass 'xlsx' as the third argument to render for spreadsheet output (the template must have the XLSX format enabled and contain a table section).
If it fails
| Error | Fix |
|---|---|
401 Missing x-api-key header / Invalid API key | The env var isn’t set or the key was mistyped/rotated |
404 Template not found | Wrong template ID (or it belongs to another organization) |
400 Template is not published | Publish the template in the dashboard first |
The full catalog with every exact message is in Errors.
downloadUrl is a presigned, time-limited URL (about an hour by default). Don’t persist it — store documentId and request GET /v1/downloads/:id when you need a fresh link. Details in Backend rendering.
Where next
- Backend rendering — patterns for server actions and APIs, error handling, download semantics.
- Frontend rendering — render straight from the browser with the public key and React hooks.
- Invoice generator tutorial — a complete end-to-end flow.