can1357/oh-my-pi · error
mime_type is required when providing raw base64 data.
Error message
mime_type is required when providing raw base64 data.
What it means
When the image URL is a data: URL, the tool parses it with normalizeDataUrl; a data: URL that carries raw base64 payload without a mime type (e.g. 'data:;base64,...' or malformed header) leaves mimeType undefined. Since providers need an explicit media type to send the inline image, the tool refuses rather than guessing. This protects the API request from being rejected for a missing/invalid media type.
Source
Thrown at packages/coding-agent/src/tools/image-gen.ts:386
}
function resolveOpenRouterModel(model: string): string {
return model.includes("/") ? model : `google/${model}`;
}
function toDataUrl(image: InlineImageData): string {
return `data:${image.mimeType};base64,${image.data}`;
}
async function loadImageFromUrl(
imageUrl: string,
fetchImpl: FetchImpl,
signal?: AbortSignal,
): Promise<InlineImageData> {
if (imageUrl.startsWith("data:")) {
const normalized = normalizeDataUrl(imageUrl.trim());
if (!normalized.mimeType) {
throw new Error("mime_type is required when providing raw base64 data.");
}
if (!normalized.data) {
throw new Error("Image data is empty.");
}
return { data: normalized.data, mimeType: normalized.mimeType };
}
const response = await fetchImpl(imageUrl, { signal });
if (!response.ok) {
const rawText = await response.text();
throw new Error(`Image download failed (${response.status}): ${rawText}`);
}
const contentType = response.headers.get("content-type")?.split(";")[0];
if (!contentType?.startsWith("image/")) {
throw new Error(`Unsupported image type from URL: ${imageUrl}`);
}
const buffer = await response.bytes();
return { data: buffer.toBase64(), mimeType: contentType };View on GitHub (pinned to 9690622007)
Solutions
- Include an explicit mime type in the data URL: `data:image/png;base64,<payload>`
- If using a generic type, use a supported one like image/png, image/jpeg, image/webp, or image/gif
- Decode and re-encode the payload with a helper that emits the mime header
- Use a file path input instead of a data: URL so the tool sniffs the type from file bytes
Example fix
// before const url = "data:;base64,iVBORw0KGgoAAA..."; // after const url = "data:image/png;base64,iVBORw0KGgoAAA...";
Defensive patterns
Strategy: validation
Validate before calling
function validateDataUrl(url: string): boolean {
const m = /^data:([\w.+-]+\/[\w.+-]+)?(;base64)?,/.exec(url);
return !!m && !!m[1]; // mime type must be present
} Type guard
function hasDataUrlMimeType(url: string): boolean {
const m = /^data:([^;,\s]+)/.exec(url.trim());
return m !== null && m[1].includes("/");
} Prevention
- Always build data URLs with an explicit `data:image/png;base64,` prefix via a helper
- Never hand-concatenate data URL strings in templates
- Run validateDataUrl on every data URL before passing it to the tool
- Prefer file-path inputs when the source is a local file
When it happens
Trigger: Passing a data: URL to image generation input images where the mime portion is empty or unparseable — e.g. `data:;base64,<payload>`, `data:image;base64,...` (missing subtype), or a truncated URL that lost its type prefix.
Common situations: Hand-built data URLs in scripts or notebooks; copy-pasted URLs where the mime type was stripped; output from encoders that omit the media type; template interpolation that dropped the `image/png,` segment.
Related errors
- Image data is empty.
- Unsupported image type: ${imagePath}
- Unknown image type: ${mimeType}
- Aspect ratio ${aspectRatio} is only supported by xAI image g
- Image file too large: ${imagePath}
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/6e0eb72aef5e9dfb.
Report an issue: GitHub.