What this lets you do
Submit an image request, preserve its identity, follow events, and recover its output without submitting replacement work. The Python and JavaScript examples use standard libraries and make the same HTTP requests.What you need
- Python 3.10+ or Node.js 22.12+
- A server-side
DREAMLAYER_API_KEYand sufficient credits for generation - Python example or JavaScript example, saved locally
Steps
1. Save a request
Createrequest.json for a first image:
sprite_sheet and sprite_pricing in capabilities. Set max_credits to a quote you approve:
2. Submit and follow
job.json with a random idempotency key and the serialized request before sending the request. It asks for a JSON acknowledgement, saves the execution ID, then reads the event stream. It persists the cursor after parsing each event and checks canonical state after every connection closes.
3. Recover after interruption
4. Download the existing result
.zip for a sprite. Downloading does not regenerate the output. The examples authenticate only to the API origin, strip credentials from redirected storage requests, and refuse to overwrite an existing destination.
Confirm it worked
The final JSON reportscompleted, the journal retains the execution ID, and the download writes the existing PNG or ZIP. A local waiting deadline or network error leaves the journal intact for a later resume.
Common errors
needs_input: readquestion, answer through the conversation API, and track the answer’s new execution ID.failedorcancelled: inspect the public error; do not automatically submit a replacement.429: back off according to limits. The examples stop on HTTP errors so your caller can apply its own bounded retry policy.- An existing journal with a different request is refused. Use a new journal only for intentionally new work.