sgl-project/sglang · error · ValueError
{b64_format_hint} (missing ;base64 marker)
Error message
{b64_format_hint} (missing ;base64 marker) What it means
The input matched the generic data-URI shape but lacked the ;base64 marker, e.g. data:image/png,.... Only base64-encoded payloads are supported, so the parser rejects URL-encoded or plain data URIs.
Source
Thrown at python/sglang/multimodal_gen/runtime/utils/image_io.py:19
# SPDX-License-Identifier: Apache-2.0
import base64
import os
import re
def save_base64_image_to_path(base64_data: str, target_path: str) -> str:
b64_format_hint = (
"Failed to decode base64 image. "
"Expected format: `data:[<media-type>];base64,<data>`"
)
match = re.match(r"data:(.*?)(;base64)?,(.*)", base64_data)
if not match:
raise ValueError(b64_format_hint)
media_type = match.group(1)
is_base64 = match.group(2)
if not is_base64:
raise ValueError(f"{b64_format_hint} (missing ;base64 marker)")
data = match.group(3)
if not data:
raise ValueError(f"{b64_format_hint} (empty data payload)")
if media_type.startswith("image/"):
ext = media_type.split("/")[-1].lower()
if ext == "jpeg":
ext = "jpg"
else:
ext = "jpg"
target_path = f"{target_path}.{ext}"
os.makedirs(os.path.dirname(target_path), exist_ok=True)
try:
image_data = base64.b64decode(data)
except Exception as exc:
raise Exception(f"Failed to decode base64 image: {str(exc)}") from exc
View on GitHub (pinned to 0132848349)
Solutions
- Base64-encode the bytes and include the marker: data:image/png;base64,...
- Ensure client libraries (e.g. canvas toDataURL) are used unchanged — they already emit ;base64
Example fix
// before
save_base64_image_to_path("data:image/png,%89PNG%0D%0A", "/tmp/img")
// after
save_base64_image_to_path("data:image/png;base64,iVBORw0KGgo...", "/tmp/img") Defensive patterns
Strategy: validation
Validate before calling
def has_base64_marker(s: str) -> bool:
return ";base64," in s Type guard
def is_base64_data_uri(s: str) -> bool:
return isinstance(s, str) and s.startswith("data:") and ";base64," in s Try / catch
try:
save_base64_image_to_path(uri, path)
except ValueError as e:
if "missing ;base64 marker" in str(e):
uri = uri.replace(",", ";base64,", 1) if uri.startswith("data:") else uri Prevention
- Always base64-encode (not URL-encode) image bytes
- Pass through browser toDataURL output unchanged
When it happens
Trigger: Supplying a data URI without ;base64 such as data:image/png,%89PNG... to _maybe_url_image / prepare_warmup_image_path.
Common situations: Clients URL-encoding image bytes instead of base64-encoding them; hand-built data URIs that omit the marker.
Related errors
- Failed to decode base64 image. Expected format: `data:[<medi
- {b64_format_hint} (empty data payload)
- No base64 image data found
- Cosmos3 action input accepts one image field; use a list or
- data URI must use ;base64 encoding
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/1e435cac7bce36b1.
Report an issue: GitHub.