linshenkx/prompt-optimizer · error · RequestConfigError

Image understanding request cannot be empty

Error message

Image understanding request cannot be empty

What it means

Thrown by validateImageUnderstandingRequest when the request argument to sendImageUnderstanding / sendImageUnderstandingStream is null, undefined, or not an object. The adapter validates the request envelope before touching the network; a missing request means the call cannot proceed. Client-side RequestConfigError.

Source

Thrown at packages/core/src/services/llm/adapters/abstract-adapter.ts:204

    for (const msg of messages) {
      if (!msg.role || !msg.content) {
        throw new RequestConfigError('Each message must have role and content')
      }

      if (!['system', 'user', 'assistant', 'tool'].includes(msg.role)) {
        throw new RequestConfigError(`Invalid message role: ${msg.role}`)
      }

      if (typeof msg.content !== 'string') {
        throw new RequestConfigError('Message content must be a string')
      }
    }
  }

  protected validateImageUnderstandingRequest(request: ImageUnderstandingRequest): void {
    if (!request || typeof request !== 'object') {
      throw new RequestConfigError('Image understanding request cannot be empty')
    }

    if (typeof request.userPrompt !== 'string' || !request.userPrompt.trim()) {
      throw new RequestConfigError('Image understanding user prompt cannot be empty')
    }

    if (!Array.isArray(request.images) || request.images.length === 0) {
      throw new RequestConfigError('Image understanding request requires at least one image')
    }

    request.images.forEach((image, index) => {
      if (!image || typeof image !== 'object') {
        throw new RequestConfigError(`Image at index ${index} is invalid`)
      }

      if (typeof image.b64 !== 'string' || !image.b64.trim()) {
        throw new RequestConfigError(`Image at index ${index} is missing base64 data`)
      }

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Pass a proper ImageUnderstandingRequest object: { userPrompt, images: [{ b64 }] }
  2. Check for undefined with a guard before invoking when the request comes from optional config
  3. Log the request payload right before the call to spot null/undefined early

Example fix

// before
await adapter.sendImageUnderstanding(base64String as any)

// after
await adapter.sendImageUnderstanding({ userPrompt: 'Describe this', images: [{ b64: base64String }] })
Defensive patterns

Strategy: type-guard

Validate before calling

if (!request || typeof request !== 'object') throw new Error('request missing')

Type guard

function isImageUnderstandingRequest(r: unknown): r is ImageUnderstandingRequest {
  return !!r && typeof r === 'object'
    && typeof (r as ImageUnderstandingRequest).userPrompt === 'string'
    && Array.isArray((r as ImageUnderstandingRequest).images)
}

Try / catch

null

Prevention

When it happens

Trigger: Calling sendImageUnderstanding(null), sendImageUnderstanding(undefined), or passing a primitive (string/number) instead of an ImageUnderstandingRequest object.

Common situations: Optional chaining that yields undefined (req?.imageRequest); passing a base64 string directly instead of wrapping it in a request object; default parameter of undefined when config loading fails.

Related errors


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