net/http makes the request, encoding/json shapes the body,
and go.mod stays empty. This page builds a small package around those two
calls, then a route that answers with a finished image.
The official client libraries are Node and Python. In Go you call
the API directly, which is what the code below does.
Rules for an agent adding SudoMock to a Go service.
Prerequisites
- Go 1.22 or newer. The route below uses method patterns in
http.ServeMux. - An API key from API keys. Keys begin with
sm_. - A PSD holding at least one smart object. See Preparing a PSD.
- The same two calls in cURL, if you want them side by side: Quickstart.
Guide
1
Set up the module
go get follows. The key lives in the environment, so it never reaches
the binary and never reaches a commit.2
Write the client
One
*http.Client serves the whole process and carries the timeout. post
is the only place the x-api-key header is set, so no later call can forget
it, and any reply that is not 200 becomes an APIError holding the status,
the error_code and the message the API returned.mockups/client.go
3
Upload the PSD once
POST /api/v1/psd/upload takes a public URL to the file and answers with the
mockup plus every layer inside it. Those layer UUIDs are what a render
addresses, so this call is also how you learn what you can change.mockups/upload.go
cmd/upload/main.go
4
Render from a route
POST /api/v1/renders takes the mockup UUID, the smart object to fill and
the artwork that goes into it. fit decides how the artwork meets the layer
area: crop covers the area and cuts the overflow while keeping proportions.mockups/render.go
main.go
data.print_files[0].export_path, the URL of the finished
image. Serve it to the page or store it against the order. A key bound to a
custom domain serves that URL from your own
domain, with nothing to pass per request.This render holds the connection until the image exists. For a long job set
is_async to true, take the job_id from the 202, and either poll
GET /api/v1/jobs/{job_id} or let a webhook call you.5
Read a failure
APIError already carries the status and the error_code, so a caller
branches on values rather than matching strings.image_size comes back as 402 with error_code OUTPUT_RESOLUTION_LIMIT
rather than a quietly smaller image.Next steps
Fit and blend modes
What
fit and blending_mode do to the result.Webhooks
Let a long render call your service back.
Errors
Every error code, and which statuses are worth retrying.