async function tryOnWithRetry(payload, retries = 3) {
for (let i = 0; i < retries; i++) {
const res = await fetch('https://api.wearo.io/functions/v1/tryon-api', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-API-Key': 'wearo_xxx' },
body: JSON.stringify(payload)
});
if (res.status !== 429) return res.json();
const retryAfter = res.headers.get('Retry-After') || (2 ** i);
await new Promise(r => setTimeout(r, retryAfter * 1000));
}
throw new Error('Rate limit exceeded after retries');
}