Retries & Idempotency
A request can time out or lose its connection after the mockup was generated and charged. Retried blind, you could pay twice. Send an Idempotency-Key header and retries are safe: a repeat of a request with the same key is never charged again, and it gets back the result of the first one.
How to use it
Make up a unique key (a UUID is ideal) for each mockup job, and send the same key on every attempt of that job:
curl -X POST https://www.mockupanda.com/api/v1/mockups/generate \
--http1.1 \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 6f1c2f9e-3b7d-4c55-9a8e-2d0b7c1e4f10" \
-d '{
"template_ids": ["TEMPLATE_ID_1", "TEMPLATE_ID_2"],
"artwork_url": "https://example.com/art.jpg",
"response_format": "hosted"
}'The key is any string of 1 to 255 printable characters without spaces. It only applies to POST /api/v1/mockups/generate.
What a retry gets back
| The first request with this key... | A retry with the same key and the same request gets |
|---|---|
| Succeeded | The same response, with the header Idempotent-Replayed: true. Nothing is rendered or charged again. Images come back as the same bytes; hosted results come back with the same links. |
| Is still running | 409 IDEMPOTENCY_KEY_IN_USE with a Retry-After header. Wait, then retry with the same key. |
| Failed (bad parameter, not enough balance, rendering error, rate limit) | A fresh attempt. A failed request is never charged and does not keep the key, so you can fix the problem (top up, correct a template id) and retry with the same key. |
A replay has its own X-Request-Id and shows in DashboardLogs as a free request. The X-Original-Request-Id header names the request that was charged.
Same key, different request
A key belongs to one request. Sending it again with different parameters (another template, another artwork file or URL, another output format) is refused, so a reused key can never hand you the wrong mockup:
{
"error": "This Idempotency-Key was already used for a different request.",
"code": "IDEMPOTENCY_KEY_REUSED",
"hint": "Send a new Idempotency-Key for each new request. Reuse a key only to retry the exact same request.",
"request_id": "013b73a7-9d8e-4a5d-9e45-251197bd75a1"
}Still running
{
"error": "A request with this Idempotency-Key is still being processed.",
"code": "IDEMPOTENCY_KEY_IN_USE",
"details": { "retry_after": 5 },
"hint": "Wait retry_after seconds, then retry with the same key to get its result.",
"request_id": "013b73a7-9d8e-4a5d-9e45-251197bd75a1"
}How long keys last
A key is remembered for 24 hours after its first request. After that, a request with the same key is treated as new and charged. Keys belong to your account, not to one API key, so a retry still matches after you rotate keys.
When to use a new key
- New job, new key. Generating the same artwork on the same templates again on purpose (say, the next day) needs a new key, or you get the first result back.
- Retry, same key. Timeouts, dropped connections,
5xxerrors,408,409and429are all safe to retry with the same key.