Errors and limits
This page covers Nooknear API error responses, rate limits, quotas and how to retry requests safely. The short rule: decide based on the HTTP status code first, then use the error code in the body for detail.
The error body
Errors are returned as JSON. error is a machine-readable code and message is a human-readable description:
{
"error": "NOT_FOUND",
"message": "Asset not found"
}
Field validation errors also include a details array showing which field was rejected and why:
{
"error": "VALIDATION_ERROR",
"message": "Invalid request data",
"details": [
{
"code": "invalid_string",
"validation": "regex",
"path": ["resourceType"],
"message": "Invalid"
}
]
}
message text can change, so don’t branch on it in code. Treat details as informational too.
Every response carries an X-Request-ID header. If you send that header yourself, the same value is echoed back. Including it in support requests helps us find the problem faster.
Status codes and error codes
| HTTP | error |
When |
|---|---|---|
400 |
VALIDATION_ERROR |
A field breaks a rule: invalid mimeType, sizeBytes over 10 MB, malformed metadata JSON, an unsupported outputFormats value and so on. |
400 |
REQUEST_ERROR |
The request was rejected before reaching the handler: a required field is missing, the body isn’t valid JSON, a value has the wrong type. |
401 |
UNAUTHORIZED |
X-API-Key is missing or invalid. Rotated (old) keys and suspended accounts also get this code. |
403 |
FORBIDDEN |
You aren’t allowed to do this, for example calling an endpoint for another tenantId. Some 403 responses contain only the error field. |
403 |
CORS_ORIGIN_NOT_ALLOWED |
The request came from an Origin that isn’t allowed for your account. |
404 |
NOT_FOUND |
The asset doesn’t exist, was deleted, or belongs to another account. |
409 |
CONFLICT |
The request conflicts with the current state. |
413 |
REQUEST_ERROR |
The request body is too large. Send files to uploadUrl, not to the API. |
429 |
RATE_LIMIT_EXCEEDED |
You hit the rate limit. See below. |
429 |
QUOTA_EXCEEDED |
The file exceeds your plan’s per-file limit or total storage quota. |
500 |
INTERNAL_ERROR |
An unexpected server error. You can retry. |
503 |
(none) | Only GET /health: a dependency (database, Redis, storage) is unhealthy. |
Whether a 400 comes back as VALIDATION_ERROR or REQUEST_ERROR depends on which layer caught it. Treat both as “fix the request before retrying”.
Direct upload (PUT) errors
The PUT to uploadUrl goes to storage (Cloudflare R2), not to the Nooknear API, so its error body is XML and doesn’t use the codes above. The most common case is 403, usually because:
- The
Content-Typeheader doesn’t match themimeTypefrom the upload request. - The URL’s 15-minute lifetime has passed.
- The URL got mangled when copied (for example,
&characters were escaped).
Fix: make a new upload request and send the file again with the right Content-Type. Details in Uploads.
CDN errors
CDN URLs return plain-text responses: 401 if the token is missing or wrong, 404 if the file doesn’t exist (not processed yet, or deleted).
Rate limits
Rate limits apply per account and per endpoint: polling GET /v1/media/:assetId, for example, doesn’t eat into your POST /v1/media/upload-request allowance. The limit is a number of requests per minute set by your plan.
Every response includes three headers:
| Header | Meaning |
|---|---|
X-RateLimit-Limit |
Requests allowed per window for this endpoint. |
X-RateLimit-Remaining |
Requests left in the current window. |
X-RateLimit-Reset |
When the window resets (Unix timestamp, seconds). |
When you exceed the limit you get 429 with RATE_LIMIT_EXCEEDED:
{ "error": "RATE_LIMIT_EXCEEDED", "message": "Rate limit exceeded" }
When you get a 429:
- If the response has a
Retry-Afterheader, wait that many seconds. - Otherwise, wait until
X-RateLimit-Reset. - If neither is present, back off exponentially (for example 1, 2, 4, 8 seconds) with a little random jitter.
Slowing down on your own as X-RateLimit-Remaining drops is better than waiting for a 429. Back off progressively when polling, and use limit=100 on large listings to cut the number of requests.
Quotas
Quotas are checked at upload-request time: the declared sizeBytes is compared with your plan’s per-file limit and your total storage quota. If either is exceeded you get 429 QUOTA_EXCEEDED and no upload URL.
Retrying won’t help with QUOTA_EXCEEDED. Instead:
- Check
storageUsedBytes,quotaBytesandquotaUsedPercentwithGET /v1/tenants/:tenantId/usage. - Delete images you no longer need with
DELETE /v1/media/:assetId. - Move to a plan with a larger quota: pricing.
There is no quota or fee for delivery bandwidth (egress); a fair-use policy applies.
Retries and idempotency
Decide whether to retry based on the status:
| Situation | Retry? |
|---|---|
| Network error, timeout | Yes, with Idempotency-Key. |
429 RATE_LIMIT_EXCEEDED |
Yes, after waiting. |
500, 502, 503, 504 |
Yes, with backoff. |
429 QUOTA_EXCEEDED |
No; fix the quota issue. |
400, 401, 403, 404, 409 |
No; fix the request or the key. |
Always send Idempotency-Key when retrying state-changing requests (POST /v1/media/upload-request, DELETE /v1/media/:assetId, PATCH /v1/tenants/:tenantId/rotate-key). If the first attempt actually succeeded, no second asset is created; you get the stored response back. Details in Authentication.
async function withRetry(fn, { attempts = 5 } = {}) {
for (let i = 0; i < attempts; i++) {
const res = await fn();
if (res.ok) return res;
const retryable = res.status === 429 || res.status >= 500;
if (!retryable) throw new Error(`${res.status} ${await res.text()}`);
const body = await res.clone().json().catch(() => ({}));
if (body.error === 'QUOTA_EXCEEDED') throw new Error('Quota exceeded');
const retryAfter = Number(res.headers.get('Retry-After'));
const reset = Number(res.headers.get('X-RateLimit-Reset'));
const wait = retryAfter > 0
? retryAfter * 1000
: reset > 0
? Math.max(0, reset * 1000 - Date.now())
: 2 ** i * 1000;
await new Promise((r) => setTimeout(r, wait + Math.random() * 250));
}
throw new Error('Out of retries');
}
const idempotencyKey = crypto.randomUUID();
const res = await withRetry(() =>
fetch('https://api.nooknear.com/v1/media/upload-request', {
method: 'POST',
headers: {
'X-API-Key': process.env.NOOKNEAR_API_KEY,
'Content-Type': 'application/json',
'Idempotency-Key': idempotencyKey
},
body: JSON.stringify({ resourceType: 'product', resourceId: '42', filename: 'cover.jpg', mimeType: 'image/jpeg', sizeBytes: 534120 })
})
);
Generate the Idempotency-Key once, outside the retry loop; a fresh key on every attempt defeats the purpose.