Skip to content
Orsnap
← All posts

Generating Images From an API Without a Design Team

A developer's walkthrough of template rendering over HTTP: version pinning, idempotency, async jobs, webhooks and the errors worth handling before launch.

A dark terminal panel branching into three generated product images
One template, many records. The API is the part that decides what happens on a retry.

The request is usually framed as a design question: "can we generate a product card for every item without hiring a designer?" The actual work is an integration question. Something already knows the product name, the price and the photo URL. The only missing piece is a service that turns that record into a file, repeatedly, without a human opening an editor.

That is a render API, and the interesting decisions are not about design. They are about what happens when the photo URL 404s, when the same request arrives twice, and when the template changes next month while the integration is still pointing at it.

The shape of a render request

Orsnap's render endpoint takes a template, a version, the field values, and the output settings. A minimal request:

curl https://orsnap.optell.com/api/v1/renders \
  -H "Authorization: Bearer $ORSNAP_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: campaign-1042-product-917" \
  -d '{
    "templateId": "tpl_7f3c",
    "version": 4,
    "modifications": {
      "headline": "Linen Tote",
      "price": "$49",
      "photo": "https://cdn.example.com/917.jpg"
    },
    "output": { "format": "png", "scale": 2, "background": "template" },
    "mode": "async"
  }'

A successful synchronous call returns the render with its files:

{
  "data": {
    "id": "rnd_...",
    "status": "succeeded",
    "format": "png",
    "pages": 1,
    "credits": 4,
    "files": [
      { "name": "linen-tote.png", "width": 2160, "height": 2160, "url": "...", "expiresAt": "..." }
    ]
  }
}

Two details are easy to miss. First, version and revision are alternatives: send a published version number, or a draft revision for testing, but not both and not neither. Second, scale is a resolution multiplier, not a quality setting; 2 doubles each edge, which is four times the pixels and four times the credits.

Pin the version, always

A template is a living document. Someone will edit the headline style next Tuesday. If the integration sends only a template ID and the service defaults to the latest published version, next Tuesday's edit silently changes every image the product renders.

Orsnap's versioning is designed for this: publishing creates an immutable version, and a render can name it explicitly. Pin the version in your configuration, and treat a version bump as a deploy. It is the same discipline as pinning a container image, and it prevents the worst class of bug in this workflow — one that produces plausible-looking output with the wrong layout.

Draft revisions are for previews and tests. They can change under you, which is exactly what you want while iterating and exactly what you do not want in production.

Make retries safe

Network calls fail, queues redeliver, and a webhook can arrive twice. A render costs credits, so a retried request that creates a second job is not harmless.

Idempotency-Key is required on the render endpoint, and it solves the duplicate-request case: send the same key for the same logical render, and the service returns the original result instead of rendering again. The key should identify the work, not the attempt — a SKU plus a campaign ID, for example, not a random UUID per call. A random key per retry defeats the purpose.

For the async path, the same principle applies at a different layer: a job that finishes and delivers a webhook should be treated as idempotent by the receiver. Store the job ID, and ignore a second delivery for a job you have already processed.

Async and webhooks

Synchronous renders are fine for a single page at 1×. A 10-page PDF at 2× or a short MP4 is not; those take long enough that an HTTP request is the wrong place to wait. Set mode to async, keep the job ID, and receive a signed webhook when the render finishes.

The webhook payload includes the same file list as the synchronous response, with links that expire. Two operational notes:

  • Verify the signature. The webhook is signed; an unverified endpoint lets anyone post a fake "render complete" to your service.
  • Do not store the file URLs as permanent links. They expire. Download the bytes and put them in your own storage if the asset needs to live on.

If a render fails, the API returns a structured error with a code and, for validation failures, a list of field-level issues. Log the code, not the prose, and map the two or three you actually expect — invalid field value, unsupported format, missing template — to decisions your application can make. Everything else should alert.

What the API does not do

The render API is a renderer, not a design tool. It does not decide your crop, your line breaks, or whether a headline fits. Those decisions live in the template, and the API merely supplies the values. That is why the template still needs a human, and why building it deliberately matters: the variable definition, the overflow policy and the fixed furniture are where quality comes from, and they are also what makes the API safe to call from a system that has never seen the design.

It also does not convert color spaces. If your output is a print PDF, the file declares PDF/X-4 and carries the trim box and output intent, but an RGB photo remains an RGB photo. A preflight pass is still the check before a printer sees it.

Cost per call is a product decision

A one-page PNG at 1× is one credit; at 2× it is four. A 10-page PDF is ten pages of work. When a storefront triggers a render on every product publish, the monthly total is the product of catalog size and publish frequency, and the plan should be chosen against that number rather than against a demo.

The practical pattern that keeps costs sane is to render on demand and cache the result: when the product record has not changed, serve the stored file; render when it has. The API is stateless enough that this is entirely your side of the integration, and it is the difference between a catalogue-sized bill and a demo-sized one.

Start with one template and one record

The fastest way to find integration problems is a single page, a single record, and the sync path. Once that returns a file you would ship, add the idempotency key, switch to async, and wire the webhook. The API reference documents the full request schema, the error table and the TypeScript SDK, and the Developers console is where you create the key and the webhook endpoint.