Skip to main content
A route handler takes an artwork URL, drops it into a Photoshop template you uploaded once, and answers with the finished image. The key stays on the server, so nothing in the browser bundle can read it.

Use this prompt to get an agent writing the call correctly.

Open in Cursor

Prerequisites

  • An API key from your dashboard. Keys start with sm_.
  • Node.js 20 or newer. The setup script below reads .env.local with --env-file, which arrived in 20.6.
  • A Next.js app, App Router or Pages Router.

Guide

1

Install

Add the Node SDK to your project.
2

Add your key

Put the key in .env.local. Next.js loads that file for you in next dev and next build, so a route handler reads it with no further setup.
.env.local
Leave the NEXT_PUBLIC_ prefix off. It inlines the value into the browser bundle, and a key in a bundle is a key anyone can copy.
3

Upload the template once

A PSD becomes a reusable template on your account, so this belongs in your setup rather than in the request path. Run it once and keep the two UUIDs it prints.
scripts/upload-mockup.mjs
The response also carries textLayers, which is how you swap copy on the same template later.
4

Render from a route handler

The handler takes an artwork URL, fills the smart object with it, and returns the image URL. Pick the tab for your router.
Every SudoMock failure arrives as a SudoMockError carrying status and code, so one branch covers a rejected key, a missing template and a rate limit alike. A connection failure or a client side timeout reports status as 0, which is why the fallback above exists.
5

Call it

Start the dev server and post an artwork URL to the route.
The reply carries one field, url, pointing at the rendered image. Feed it to next/image, attach it to the order, or store it. When a render fills several smart objects, render.printFiles holds one entry per filled layer, each with its own exportPath.
A render that outlives your function time limit is better submitted in the background. Pass isAsync: true to renders.create, answer the request straight away, and let a webhook tell you when the image is ready.

Next steps

Fit and blend modes

What fit and blending_mode do to the artwork you place.

Webhooks

Get called back when a background render finishes.

Errors

Every status and error_code, and which ones are worth a retry.

Node SDK

The rest of the client: templates, photo mockups, jobs, fonts.