linshenkx/prompt-optimizer · error · Error
Unable to build model ${configForm.value.modelId}: ${error i
Error message
Unable to build model ${configForm.value.modelId}: ${error instanceof Error ? error.message : String(error)} What it means
While testing a connection, useImageModelManager needs a model instance. When the model ID isn't in the registry cache it falls back to adapter.buildDefaultModel(modelId); if that builder throws (unknown model ID, malformed ID, adapter limits), the error is rethrown wrapped with context about which model failed.
Source
Thrown at packages/ui/src/composables/model/useImageModelManager.ts:436
const parts: string[] = []
if (detail.missing.length) parts.push(t('image.connection.validation.missing', { fields: detail.missing.join(', ') }))
if (detail.typeErrors.length) {
parts.push(detail.typeErrors.map(e => t('image.connection.validation.invalidType', e)).join('; '))
}
connectionStatus.value = { type: 'error', messageKey: 'image.connection.testFailed', detail: parts.join('; ') }
toast.error(parts.join('; '))
return
}
// 获取选中的模型信息:优先使用缓存,不存在时通过registry构建
let selectedModel = models.value.find(m => m.id === configForm.value.modelId)
if (!selectedModel) {
// 对于自定义模型ID,使用adapter的buildDefaultModel方法构建
try {
const adapter = registry.getAdapter(selectedProviderId.value)
selectedModel = adapter.buildDefaultModel(configForm.value.modelId)
} catch (error) {
throw new Error(
`Unable to build model ${configForm.value.modelId}: ${error instanceof Error ? error.message : String(error)}`,
{ cause: error }
)
}
}
// 根据模型能力确定测试类型
const testType = selectTestType(selectedModel)
// 构建完整的模型配置
const completeConfig: ImageModelConfig = {
id: configForm.value.id || 'test',
name: configForm.value.name || 'Test Config',
providerId: selectedProviderId.value,
modelId: configForm.value.modelId,
enabled: true,
connectionConfig: configForm.value.connectionConfig || {},
paramOverrides: configForm.value.paramOverrides || {},View on GitHub (pinned to 3e677b1d9f)
Solutions
- Check the model ID against the provider's model list and correct typos before testing.
- Update the adapter (or the package) to a version that recognizes the model ID.
- If the model should be buildable, inspect the cause in the wrapped error's { cause } to see the underlying builder failure.
Example fix
// before
adapter.buildDefaultModel('flux--pro') // throws
// after
adapter.buildDefaultModel('flux-pro') // verify ID against provider docs/model list Defensive patterns
Strategy: try-catch
Validate before calling
const ids = adapter.listModels?.() ?? []
if (!ids.includes(configForm.value.modelId)) { /* warn before test */ } Try / catch
try { await testConnection() } catch (e) { if (e instanceof Error && e.message.startsWith('Unable to build model')) { console.error(e.cause); showModelIdError(e.message); return } throw e } Prevention
- Validate custom model IDs against the provider's model list
- Keep adapters updated when adopting new models
- Inspect error.cause for the underlying builder failure
When it happens
Trigger: Entering a custom model ID in the image provider config and clicking 'Test Connection' when the provider's adapter cannot construct a default model for that ID — e.g. ID doesn't match any known model pattern or the adapter requires extra parameters.
Common situations: Typos in custom model IDs; using a model name from a newer API version than the adapter supports; provider-specific naming conventions (dashes vs dots) not honored.
Related errors
- Unable to build model ${selectedModelId.value}: ${error inst
- Image understanding service is not available for multimodal
- Image storage service is required to resolve evaluation imag
- Model metadata cannot be empty
- Model provider metadata cannot be empty
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/50745bb12c214605.
Report an issue: GitHub.