Hono icon

Hono

Put the render call behind a Hono route and your API key never reaches the browser. Imejis returns the finished image directly in the response, so the handler is a single upstream request, with nothing to poll and no webhook to receive.

Set two environment variables first: IMEJIS_API_KEY (from your dashboard) and IMEJIS_DESIGN_ID (any design's id). The fields you override are component.property pairs: headline.text, title.color, image.image; only what you send changes, and a design's overridable fields are listed in its Share / API panel.

Each route below comes from a real Hono app that is booted in Docker and called end to end before this page ships.

An endpoint that returns the generated imageAn endpoint that returns the generated image

A route in your app that renders on demand and streams the image straight back, so your render key never reaches the browser. This is the shape to use behind an <img src> on a page you control. ?format= picks png, jpeg, webp or pdf, and the route answers with the content type that matches it. A PDF labelled image/png is a file the browser, the email client and Slack all refuse to open.

Hono: An endpoint that returns the generated image
import { Hono } from "hono"
 
const app = new Hono()
 
const API_KEY = Bun.env.IMEJIS_API_KEY
const DESIGN_ID = Bun.env.IMEJIS_DESIGN_ID
const BASE = Bun.env.IMEJIS_RENDER_URL ?? "https://render.imejis.io"
const HEADERS = { "dma-api-key": API_KEY!, "Content-Type": "application/json" }
 
// The formats the render API accepts. The routes below pass `?format=`
// through when one is asked for; with none, the render host's default (jpeg)
// applies.
const FORMATS = ["png", "jpeg", "webp", "pdf"]
 
// Render on demand and stream the image straight back. The render key stays on
// the server, so it never reaches the browser — point an <img src> at this.
//
// `?format=` decides what comes back — png · jpeg · webp · pdf — and with no
// format the render host's default (jpeg) applies. Either way the response
// carries whatever type the render API set, passed straight through: a PDF
// labelled `image/jpeg` is a file the browser, the email client and Slack all
// refuse to open.
app.get("/og", async (c) => {
  const params = new URLSearchParams()
  const requested = c.req.query("format")
  if (FORMATS.includes(requested ?? "")) params.set("format", requested!)
 
  const upstream = await fetch(`${BASE}/v1/${DESIGN_ID}?${params}`, {
    method: "POST",
    headers: HEADERS,
    body: JSON.stringify({
      "headline.text": c.req.query("title") ?? "Hello from Hono",
      "subtitle.text": c.req.query("subtitle") ?? "",
    }),
  })
  if (!upstream.ok) {
    return c.json({ error: `render failed: ${upstream.status}` }, 502)
  }
  return c.body(await upstream.arrayBuffer(), 200, {
    "Content-Type": upstream.headers.get("content-type") ?? "image/jpeg",
    // Cache it: the same query renders the same image, and every request to
    // the render API is one metered render.
    "Cache-Control": "public, immutable, no-transform, max-age=31536000",
  })
})
 
export default app

One endpoint every size and jpeg qualityOne endpoint, every size, and JPEG quality

A multi-size design carries several canvases: an OG image, a square post, a vertical story. ?variation=<id> picks which one the route renders, and omitting it gives the base size, so one endpoint serves every size your pages ask for. ?quality= trades file size for fidelity on JPEG only; png, webp and pdf ignore it.

Hono: One endpoint, every size, and JPEG quality
import { Hono } from "hono"
 
const app = new Hono()
 
const API_KEY = Bun.env.IMEJIS_API_KEY
const DESIGN_ID = Bun.env.IMEJIS_DESIGN_ID
const BASE = Bun.env.IMEJIS_RENDER_URL ?? "https://render.imejis.io"
const HEADERS = { "dma-api-key": API_KEY!, "Content-Type": "application/json" }
 
// The formats the render API accepts. The routes below pass `?format=`
// through when one is asked for; with none, the render host's default (jpeg)
// applies.
const FORMATS = ["png", "jpeg", "webp", "pdf"]
 
// One design, several canvases — an OG image, a square post, a vertical
// story. `?variation=<id>` picks which one you get; with none you get the
// base size. Map YOUR OWN size names to the ids (the design's Share / API
// panel lists them) so a page asks for "story", not for an id.
//
// `?quality=` trades file size for fidelity on JPEG only — png, webp and pdf
// ignore it.
const SIZES: Record<string, string | null> = {
  og: null,
  story: Bun.env.IMEJIS_VARIATION_ID ?? "story",
}
 
app.get("/og-size", async (c) => {
  const size = c.req.query("size") ?? "og"
  if (!(size in SIZES)) return c.json({ error: `unknown size: ${size}` }, 404)
 
  const params = new URLSearchParams()
  const variation = SIZES[size]
  if (variation) params.set("variation", variation)
  const requested = c.req.query("format")
  if (FORMATS.includes(requested ?? "")) params.set("format", requested!)
  const quality = Number(c.req.query("quality"))
  if (quality >= 1 && quality <= 100) params.set("quality", String(quality))
 
  const upstream = await fetch(`${BASE}/v1/${DESIGN_ID}?${params}`, {
    method: "POST",
    headers: HEADERS,
    body: JSON.stringify({ "headline.text": c.req.query("title") ?? "Every size" }),
  })
  if (!upstream.ok) {
    return c.json({ error: `render failed: ${upstream.status}` }, 502)
  }
  return c.body(await upstream.arrayBuffer(), 200, {
    "Content-Type": upstream.headers.get("content-type") ?? "image/jpeg",
    "Cache-Control": "public, immutable, no-transform, max-age=31536000",
  })
})
 
export default app

An endpoint that returns a hosted or signed image urlAn endpoint that returns a hosted or signed image URL

Ask for ?delivery=hosted (a public URL) or ?delivery=signed (a private, expiring one) and hand the URL to the caller instead of the bytes, which is what you want for an email, a webhook payload, or a share card.

Hono: An endpoint that returns a hosted or signed image URL
import { Hono } from "hono"
 
const app = new Hono()
 
const API_KEY = Bun.env.IMEJIS_API_KEY
const DESIGN_ID = Bun.env.IMEJIS_DESIGN_ID
const BASE = Bun.env.IMEJIS_RENDER_URL ?? "https://render.imejis.io"
const HEADERS = { "dma-api-key": API_KEY!, "Content-Type": "application/json" }
 
// The formats the render API accepts. The routes below pass `?format=`
// through when one is asked for; with none, the render host's default (jpeg)
// applies.
const FORMATS = ["png", "jpeg", "webp", "pdf"]
 
// Ask for a stored URL instead of bytes. `hosted` is public and permanent;
// `signed` is private and expires (`expiresIn` is minutes).
app.get("/og-url", async (c) => {
  const delivery = c.req.query("private") ? "signed" : "hosted"
  const params = new URLSearchParams({ delivery })
  // The stored URL carries the extension of the format it was rendered in, so
  // pass the format through here too — a recipient that sniffs by extension
  // (an email client, a Slack unfurl) needs `.pdf` to say pdf.
  const requestedFormat = c.req.query("format")
  if (FORMATS.includes(requestedFormat ?? "")) {
    params.set("format", requestedFormat!)
  }
  if (delivery === "signed") params.set("expiresIn", "30")
 
  const upstream = await fetch(`${BASE}/v1/${DESIGN_ID}?${params}`, {
    method: "POST",
    headers: HEADERS,
    body: JSON.stringify({ "headline.text": c.req.query("title") ?? "Shared card" }),
  })
  const stored = await upstream.json()
  return c.json({
    url: stored.url,
    format: stored.format,
    expiresAt: stored.expiresAt ?? null,
  })
})
 
export default app

Bulk image generation from a routeBulk image generation from a route

One POST to /bulk renders many images, a row per record or one per size, and returns a URL for each, in the order you sent them.

Hono: Bulk image generation from a route
import { Hono } from "hono"
 
const app = new Hono()
 
const API_KEY = Bun.env.IMEJIS_API_KEY
const DESIGN_ID = Bun.env.IMEJIS_DESIGN_ID
const BASE = Bun.env.IMEJIS_RENDER_URL ?? "https://render.imejis.io"
const HEADERS = { "dma-api-key": API_KEY!, "Content-Type": "application/json" }
 
// The formats the render API accepts. The routes below pass `?format=`
// through when one is asked for; with none, the render host's default (jpeg)
// applies.
const FORMATS = ["png", "jpeg", "webp", "pdf"]
 
// One POST renders many images and returns a URL for each, in the order sent —
// a row per record, or one per size.
app.post("/cards", async (c) => {
  const { rows = [] } = await c.req.json()
  const upstream = await fetch(`${BASE}/bulk`, {
    method: "POST",
    headers: HEADERS,
    body: JSON.stringify({
      designId: DESIGN_ID,
      delivery: "hosted",
      format: "png",
      data: rows.map((row: { name: string; role: string }) => ({
        "headline.text": row.name,
        "subtitle.text": row.role,
      })),
    }),
  })
  const bulk = await upstream.json()
  return c.json({
    summary: bulk.summary,
    urls: bulk.results.map((r: { url?: string }) => r.url ?? null),
  })
})
 
export default app

Using the image url directly in a templateUsing the image URL directly in a template

For a public design you can skip the proxy entirely and point an <img> at the render URL with the field values in the query string. Keep the proxy when the key must stay private. That is the right default.

Hono: Using the image URL directly in a template
import { Hono } from "hono"
 
const app = new Hono()
 
const API_KEY = Bun.env.IMEJIS_API_KEY
const DESIGN_ID = Bun.env.IMEJIS_DESIGN_ID
const BASE = Bun.env.IMEJIS_RENDER_URL ?? "https://render.imejis.io"
const HEADERS = { "dma-api-key": API_KEY!, "Content-Type": "application/json" }
 
// The formats the render API accepts. The routes below pass `?format=`
// through when one is asked for; with none, the render host's default (jpeg)
// applies.
const FORMATS = ["png", "jpeg", "webp", "pdf"]
 
// For a PUBLIC design you can skip the proxy and point an <img> straight at
// the render URL. Keep the proxy whenever the key must stay private — that is
// the right default, and what /og above is for.
app.get("/card", (c) => {
  const url = new URL(`${BASE}/v1/${DESIGN_ID}`)
  url.searchParams.set("dma-api-key", API_KEY!)
  url.searchParams.set("headline.text", c.req.query("title") ?? "Straight from a URL")
  return c.html(`<img src="${url}" width="1200" height="630" alt="Generated card" />`)
})
 
export default app

The response is the raw image (`image/jpeg` by default). Choose the format with `?format=png|jpeg|webp|pdf` (default jpeg) and set JPEG quality with `?quality=1-100`. Store the result and get a URL back with `?delivery=hosted` (or `?delivery=signed&expiresIn=60`), and render a specific size of a multi-size design with `?variation=<id>`.

ParameterValuesDefaultWhat it does
?format=png · jpeg · webp · pdfjpegOutput image format.
?quality=1–100noneCompression quality for lossy output; ignored for other formats. (JPEG only)
?delivery=stream · hosted · signedstreamstream = raw image bytes (default); hosted = store + return a public URL; signed = store + return a time-limited URL.
?expiresIn=minutes60Signed-URL lifetime in minutes (default 60, max 10080 = 7 days). (delivery=signed only)
?variation=<size id>masterWhich multi-dimension SIZE to render. Omit or use "master" for the base size; an unknown id falls back to the master. (multi-size designs only)
  • PNG (?format=png): Lossless, supports transparency. Largest file.
  • JPEG (?format=jpeg): Smaller, lossy, no transparency. Quality adjustable.
  • WebP (?format=webp): Smallest, supports transparency. Modern browsers.
  • PDF (?format=pdf): Vector page, for print and documents.

See the delivery modes and generate images with the API guides.

These routes run on Bun here; the plain-Bun page has the same calls with no framework at all, and Express has them in Node. c.body takes the finished ArrayBuffer, so the whole image lands in memory first. Every request is one render against your quota, which starts at 100 a month free; see pricing.