sgl-project/sglang · error · HTTPException
Invalid request body: {e}
Error message
Invalid request body: {e} What it means
Thrown when constructing MeshGenerationsRequest from the request body fails, or when saving an inline/base64 image source raised. Any exception inside the body-parsing block (including image saving) is converted to HTTP 400 'Invalid request body'.
Source
Thrown at python/sglang/multimodal_gen/runtime/entrypoints/openai/mesh_api.py:205
try:
body = await request.json()
except Exception:
body = {}
try:
payload: Dict[str, Any] = dict(body or {})
if payload.get("input_image"):
img_src = payload.pop("input_image")
uploads_dir = os.path.join("outputs", "uploads")
os.makedirs(uploads_dir, exist_ok=True)
input_path = await save_image_to_path(
img_src,
os.path.join(uploads_dir, f"{request_id}_input_image"),
)
req = MeshGenerationsRequest(**payload)
except Exception as e:
raise HTTPException(status_code=400, detail=f"Invalid request body: {e}")
if not input_path:
raise HTTPException(
status_code=422,
detail="An input image is required for mesh generation",
)
sampling_params = _build_sampling_params_from_request(request_id, req, input_path)
job = _mesh_job_from_sampling(request_id, req, sampling_params)
await MESH_STORE.upsert(request_id, job)
batch = prepare_request(
server_args=server_args,
sampling_params=sampling_params,
)
asyncio.create_task(_dispatch_job_async(request_id, batch))
return MeshResponse(**job)View on GitHub (pinned to 0132848349)
Solutions
- Validate the request body against the MeshGenerationsRequest schema (required fields, types) before sending
- Check the endpoint's request model definition for required vs optional fields
- Ensure the image field (file or source) is provided in the accepted form
Example fix
// before
{"model": "mesh-model", "prompt": 123}
// after
{"model": "mesh-model", "prompt": "generate 3d mesh"} Defensive patterns
Strategy: validation
Validate before calling
# client-side: check required fields before POST
assert isinstance(body.get('model'), str) and body.get('model')
assert isinstance(body.get('prompt', 'generate 3d mesh'), str) Try / catch
if resp.status_code == 400 and 'Invalid request body' in detail:
log(resp.text); fix schema per MeshGenerationsRequest Prevention
- Mirror MeshGenerationsRequest fields in client types
- Log full detail message — it includes the Pydantic error
When it happens
Trigger: POST /mesh/generations with a JSON body missing required fields, wrong field types, unknown keys rejected by the Pydantic model, or a malformed image source reference.
Common situations: Sending extra parameters the model doesn't define; passing a non-string model id; typo'd field names like 'promt'; using an API version whose request schema changed.
Related errors
- Failed to process image source: {str(e)}
- An input image is required for mesh generation
- Mesh not found
- Mesh has been uploaded to cloud storage. Please use the clou
- Generation is still in-progress
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/d5a7e08ab80bca52.
Report an issue: GitHub.