linshenkx/prompt-optimizer · error · RequestConfigError

Model config cannot be empty

Error message

Model config cannot be empty

What it means

Thrown by validateRequest when request.modelConfig is falsy. The image understanding pipeline needs a model config to select the adapter and build runtime parameters, so a request without modelConfig is rejected before dispatch.

Source

Thrown at packages/core/src/services/image-understanding/service.ts:47

    callbacks: StreamHandlers
  ) {
    this.validateRequest(request)

    const providerId = request.modelConfig.providerMeta.id
    const adapter = this.registry.getAdapter(providerId)
    const runtimeRequest = await this.prepareRuntimeRequest(request)

    await adapter.sendImageUnderstandingStream(runtimeRequest, request.modelConfig, callbacks)
  }

  private validateRequest(request: ImageUnderstandingExecutionRequest): void {
    if (!request || typeof request !== 'object') {
      throw new RequestConfigError('Image understanding request cannot be empty')
    }

    const modelConfig = request.modelConfig
    if (!modelConfig) {
      throw new RequestConfigError('Model config cannot be empty')
    }

    if (!modelConfig.providerMeta?.id) {
      throw new RequestConfigError('Model provider metadata cannot be empty')
    }

    if (!modelConfig.modelMeta?.id) {
      throw new RequestConfigError('Model metadata cannot be empty')
    }

    if (!modelConfig.enabled) {
      throw new RequestConfigError('Model is not enabled')
    }
  }

  private async prepareRuntimeRequest(
    request: ImageUnderstandingExecutionRequest
  ): Promise<ImageUnderstandingExecutionRequest> {

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Attach the resolved model config (the same object you use for text models) to request.modelConfig.
  2. Fetch the config from ImageModelManager first and fail early if not found.
  3. Type the request builder so TypeScript flags the missing field.

Example fix

// before
await service.understand({ images, prompt } as any)

// after
const modelConfig = await modelManager.getEnabledModel(modelKey)
await service.understand({ images, prompt, modelConfig })
Defensive patterns

Strategy: validation

Validate before calling

if (!request?.modelConfig) {
  request.modelConfig = await modelManager.getEnabledModel(provider, model)
}

Type guard

const hasModelConfig = (r: unknown): r is ImageUnderstandingExecutionRequest =>
  typeof r === 'object' && r !== null && 'modelConfig' in r && (r as any).modelConfig != null

Try / catch

try { await service.understand(req) } catch (e) { if (e instanceof RequestConfigError) { /* log and fix request shape */ } throw e }

Prevention

When it happens

Trigger: Calling understand({ images, prompt } as any) with no modelConfig; passing a request whose modelConfig field was dropped by destructuring/spreading mistakes.

Common situations: Refactoring the request type and forgetting to populate modelConfig; building requests from an LLM-selected model variable that resolved to undefined.

Related errors


AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27). Data as JSON: /api/errors/5534e612d57c74ad. Report an issue: GitHub.