linshenkx/prompt-optimizer · error · RequestConfigError
Image at index ${index} is missing base64 data
Error message
Image at index ${index} is missing base64 data What it means
Thrown by validateImageUnderstandingRequest when an image object's b64 field is not a string or is empty/whitespace-only. The adapter requires actual base64 image data for each entry; missing data means the request cannot be encoded. Client-side RequestConfigError that names the failing index.
Source
Thrown at packages/core/src/services/llm/adapters/abstract-adapter.ts:221
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逻辑迁移
*
* @param content 原始内容
* @returns 处理后的结果 {content: 主要内容, reasoning?: 推理内容}
*/
protected processThinkTags(content: string): { content: string; reasoning?: string } {
// 如果内容不包含think标签,直接返回
if (!content.includes('<think>')) {
return { content }
}View on GitHub (pinned to 3e677b1d9f)
Solutions
- Convert Buffers/ArrayBuffers explicitly: buffer.toString('base64')
- Verify the property name is exactly b64 and that file reading succeeded before building the image object
- Filter/validate entries with a guard checking typeof b64 === 'string' && b64.trim().length > 0
Example fix
// before
images: [{ b64: fileBuffer }]
// after
images: [{ b64: fileBuffer.toString('base64') }] Defensive patterns
Strategy: validation
Validate before calling
const images = request.images
.filter(i => i && typeof i.b64 === 'string' && i.b64.trim().length > 0)
if (images.length === 0) throw new Error('no images with data') Type guard
function hasB64Data(i: unknown): i is { b64: string } {
return !!i && typeof i === 'object'
&& typeof (i as { b64: string }).b64 === 'string'
&& (i as { b64: string }).b64.trim().length > 0
} Try / catch
null
Prevention
- Convert Buffer/Uint8Array with .toString('base64') before assigning b64
- Verify file reads succeeded before building image entries
- Confirm the property name is exactly b64
When it happens
Trigger: images[i].b64 is undefined, '', ' ', or a Buffer/Uint8Array instead of a base64 string; reading the wrong property name (base64, data) from an upload result.
Common situations: File-read step failed silently and b64 was never set; property name mismatch with backend response (data vs b64); passing a Buffer without .toString('base64').
Related errors
- Favorite metadata cannot contain inline image data URLs (${p
- Image understanding request cannot be empty
- Image understanding user prompt cannot be empty
- Image understanding request requires at least one image
- Image at index ${index} is invalid
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/29735ac74aa99ec5.
Report an issue: GitHub.