Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
状态机、退避间隔、终态处理和三天素材有效期
queued
processing
succeeded
result.images
failed
error
cancelled
5 秒 → 8 秒 → 13 秒 → 20 秒 → 30 秒 → 之后每 30 秒一次
async function waitForTask(taskId, apiKey) { const delays = [5000, 8000, 13000, 20000, 30000]; const startedAt = Date.now(); let attempt = 0; while (Date.now() - startedAt < 15 * 60 * 1000) { const delay = delays[Math.min(attempt, delays.length - 1)]; await new Promise(resolve => setTimeout(resolve, delay)); const response = await fetch( `https://api.ch88.cn/v1/open/tasks/${encodeURIComponent(taskId)}`, { headers: { Authorization: `Bearer ${apiKey}` } }, ); if (response.status === 429) { const retryAfter = Number(response.headers.get('Retry-After')) || 30; await new Promise(resolve => setTimeout(resolve, retryAfter * 1000)); continue; } if (!response.ok) { throw new Error(`查询失败:${response.status} ${await response.text()}`); } const responseBody = await response.json(); const task = responseBody.data; if (task.status === 'succeeded') return task; if (task.status === 'failed' || task.status === 'cancelled') { throw new Error(JSON.stringify(task.error ?? { status: task.status })); } attempt += 1; } throw new Error('等待任务超时,任务可能仍在后台处理'); }
result.images[].url
<img>
curl --location '<RESULT_IMAGE_URL>' --output result.png
expires_at
null