linshenkx/prompt-optimizer · error · RequestConfigError
Model metadata cannot be empty
Error message
Model metadata cannot be empty
What it means
Thrown by validateModelConfig when the model config has no modelMeta or modelMeta.id. The service needs the model metadata (e.g. model name 'gpt-4o') to build the runtime request payload. A config missing modelMeta cannot produce a valid completion request.
Source
Thrown at packages/core/src/services/llm/service.ts:70
}
});
}
/**
* 验证模型配置
*/
private validateModelConfig(
modelConfig: TextModelConfig,
options: { allowDisabled?: boolean } = {}
): void {
if (!modelConfig) {
throw new RequestConfigError('Model config cannot be empty');
}
if (!modelConfig.providerMeta || !modelConfig.providerMeta.id) {
throw new RequestConfigError('Model provider metadata cannot be empty');
}
if (!modelConfig.modelMeta || !modelConfig.modelMeta.id) {
throw new RequestConfigError('Model metadata cannot be empty');
}
// Default behavior: disabled models cannot be used for normal requests.
// Connection testing is allowed to bypass this check (align with image model test behavior).
if (!options.allowDisabled && !modelConfig.enabled) {
throw new RequestConfigError('Model is not enabled');
}
}
/**
* 发送消息(结构化格式)
*/
async sendMessageStructured(messages: Message[], provider: string): Promise<LLMResponse> {
try {
if (!provider) {
throw new RequestConfigError('Model provider cannot be empty');
}
const modelConfig = await this.modelManager.getModel(provider);View on GitHub (pinned to 3e677b1d9f)
Solutions
- Ensure the config includes modelMeta: { id: '<model-name>' } with a non-empty id
- Verify the UI/seed flow persists modelMeta alongside providerMeta
- Validate configs once at load time and reject/repair entries missing modelMeta before runtime calls
Example fix
// before
const config = { providerMeta: { id: 'openai' } };
// after
const config = { providerMeta: { id: 'openai' }, modelMeta: { id: 'gpt-4o' } }; Defensive patterns
Strategy: validation
Validate before calling
function hasModelMeta(c: ModelConfig | undefined | null): boolean {
return !!c && !!c.modelMeta && !!c.modelMeta.id;
} Type guard
function isCompleteModelConfig(c: unknown): c is ModelConfig {
const m = c as ModelConfig;
return !!m?.providerMeta?.id && !!m?.modelMeta?.id;
} Try / catch
catch (e) { if (e instanceof RequestConfigError && /Model metadata/.test(e.message)) { /* prompt model selection / repair config */ } } Prevention
- Require model selection before saving a provider config
- Schema-validate persisted config JSON (e.g. zod) at load time
- Test config round-trip (save → load) in CI
When it happens
Trigger: Calling sendMessageStructured, sendMessageStream, sendMessageStreamWithTools, or testConnection where modelManager.getModel(provider) returns a config with modelMeta undefined or modelMeta.id empty. Common with hand-built configs or configs deserialized from older storage formats.
Common situations: Partial config objects in unit tests; JSON configs where the model identifier field was renamed; configs created via a UI flow that saved before the model was selected; imports from another tool that only capture provider info.
Related errors
- Model provider metadata cannot be empty
- Data must be an object
- Model config cannot be empty
- Model provider metadata cannot be empty
- Model metadata cannot be empty
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/9b467c41fa15b2b7.
Report an issue: GitHub.