linshenkx/prompt-optimizer · error · RequestConfigError

Image understanding request cannot be empty

Error message

Image understanding request cannot be empty

What it means

Thrown by ImageUnderstandingService.validateRequest when the request argument is null/undefined or not an object. validateRequest runs at the top of understand/understandStream and enforces a minimal request shape before any adapter work.

Source

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

    return await adapter.sendImageUnderstanding(runtimeRequest, request.modelConfig)
  }

  async understandStream(
    request: ImageUnderstandingExecutionRequest,
    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')
    }

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Pass a fully-formed ImageUnderstandingExecutionRequest object with at least modelConfig and inputs.
  2. Guard at the call site: if (!request) return early instead of invoking the service.
  3. Default the parameter: understand(request ?? buildDefaultRequest()).

Example fix

// before
await service.understand(req ?? (null as any)) // throws

// after
if (!req) throw new Error('request missing')
await service.understand(req)
Defensive patterns

Strategy: validation

Validate before calling

if (!request || typeof request !== 'object') {
  throw new TypeError('request required')
}
await service.understand(request)

Type guard

const isExecutionRequest = (r: unknown): r is ImageUnderstandingExecutionRequest =>
  typeof r === 'object' && r !== null && 'modelConfig' in r

Prevention

When it happens

Trigger: Calling understand(null), understand(undefined), or understand('prompt' as any); a variable that was expected to be built earlier but was never assigned.

Common situations: Optional chaining that short-circuits to undefined ({...userInput}?.request); async builders that return undefined on early exits; default parameter values missing.

Related errors


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