linshenkx/prompt-optimizer · error · RequestConfigError

Image understanding request requires at least one image

Error message

Image understanding request requires at least one image

What it means

Thrown by validateImageUnderstandingRequest when request.images is missing, not an array, or an empty array. The image-understanding call needs at least one image to analyze; with none there is nothing to send. Client-side RequestConfigError raised before any network request.

Source

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

      }

      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`)
      }
    })
  }

  // ===== 工具方法 =====

  /**
   * 处理<think>标签,分离推理内容和主要内容
   * 从现有service.ts中的processStreamContentWithThinkTags逻辑迁移

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Skip or short-circuit the API call when no images were successfully collected
  2. Wrap a single image in an array: images: [image]
  3. Validate Array.isArray(images) && images.length > 0 before calling

Example fix

// before
await adapter.sendImageUnderstanding({ userPrompt, images: [] })

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

Strategy: validation

Validate before calling

if (!Array.isArray(request.images) || request.images.length === 0) {
  // skip the call or notify the user instead of hitting the API
  return
}

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: Calling sendImageUnderstanding with images: [], images: undefined, or images set to a single object instead of an array of objects.

Common situations: Upstream attachment step failed or user attached no file but the call proceeds anyway; images built via filter() that removed all invalid entries; passing a single image object rather than an array.

Related errors


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