linshenkx/prompt-optimizer · error · ImageError
GENERATION_FAILED
GENERATION_FAILED
Error message
${errorMessage} What it means
When submitting an image task to ModelScope, a non-ok HTTP response causes generateImage to throw GENERATION_FAILED with the message extracted from the error body (errorData.message or errorData.error.message), defaulting to a status-based message.
Source
Thrown at packages/core/src/services/image/adapters/modelscope.ts:167
headers: {
'Authorization': `Bearer ${config.connectionConfig?.apiKey}`,
'Content-Type': 'application/json',
'X-ModelScope-Async-Mode': 'true' // 异步模式
},
body: JSON.stringify(payload)
})
if (!response.ok) {
let errorMessage = `ModelScope API error: ${response.status} ${response.statusText}`
try {
const errorData = await response.json()
if (errorData.message || errorData.error?.message) {
errorMessage = errorData.message || errorData.error.message
}
} catch {
// 忽略 JSON 解析错误
}
throw new ImageError(IMAGE_ERROR_CODES.GENERATION_FAILED, errorMessage)
}
const submitData = await response.json()
const taskId = submitData.task_id
if (!taskId) {
throw new ImageError(IMAGE_ERROR_CODES.GENERATION_FAILED, 'No task_id received from ModelScope API')
}
// 轮询任务状态
return await this.pollTaskResult(taskId, config, 120, 3000)
}
/**
* 轮询任务结果
*/
private async pollTaskResult(
taskId: string,View on GitHub (pinned to 3e677b1d9f)
Solutions
- Read the embedded errorMessage from the API response body
- Verify the ModelScope API token in config
- Confirm the modelId exists on ModelScope and supports image generation
- Adjust generation parameters to the model's supported ranges
Defensive patterns
Strategy: try-catch
Validate before calling
if (!config.apiKey) throw new Error('ModelScope token required')
if (!/^[\w.-]+\/[\w.-]+$/.test(config.modelId)) throw new Error('ModelScope modelId should look like org/model') Try / catch
try { ... } catch (e) {
if (e instanceof ImageError && e.code === IMAGE_ERROR_CODES.GENERATION_FAILED)
handleModelScopeError(e.message) // auth vs params vs server
} Prevention
- Validate ModelScope token at startup
- Use exact model IDs from ModelScope model hub
- Keep parameters within the model's documented ranges
When it happens
Trigger: POSTing the task-submit request to ModelScope and receiving 4xx/5xx — invalid API token (ModelScope token auth), invalid model ID, invalid parameters, or server errors.
Common situations: Missing/expired ModelScope access token, using a model ID that doesn't exist on ModelScope, or parameter values out of the model's allowed range.
Related errors
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/d24851fe4b333e0c.
Report an issue: GitHub.