Use this prompt to get an agent writing the call correctly.
Prerequisites
- An API key from your dashboard. Keys start with
sm_. - Node.js 20 or newer. The setup script below reads
.env.localwith--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 Leave the
.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
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.The response also carries
scripts/upload-mockup.mjs
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.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.