sgl-project/sglang · error · HTTPException

Invalid request body: {e}

Error message

Invalid request body: {e}

What it means

Raised by the SGLang video generation OpenAI-compatible endpoint when the JSON request body cannot be parsed or fails validation into a VideoGenerationsRequest. Any exception while decoding the body, resolving an input image reference, or constructing the Pydantic request model is re-raised as an HTTP 400 with the underlying message. It is a client-side validation error, not a server fault.

Source

Thrown at python/sglang/multimodal_gen/runtime/entrypoints/openai/video_api.py:816

            if payload.get("reference_url") and not _is_probably_video_source(
                payload.get("reference_url")
            ):
                try:
                    input_path = await _save_first_input_image(
                        payload.get("reference_url"),
                        request_id,
                        uploads_dir,
                        prefer_remote_source=server_args.input_save_path is None,
                    )
                except Exception as e:
                    raise HTTPException(
                        status_code=400,
                        detail=f"Failed to process image source: {str(e)}",
                    )
                payload["input_reference"] = input_path
            req = VideoGenerationsRequest(**payload)
        except Exception as e:
            raise HTTPException(status_code=400, detail=f"Invalid request body: {e}")

    # Resolve per-request output_path override
    effective_output_path = req.output_path or server_args.output_path
    if effective_output_path is None:
        output_tmp = tempfile.mkdtemp(prefix="sglang_output_")
        temp_dirs.append(output_tmp)
        effective_output_path = output_tmp
        output_persistent = False

    # Inject resolved output_path so _build_video_sampling_params picks it up
    req.output_path = effective_output_path

    logger.debug(f"Server received from create_video endpoint: req={req}")

    try:
        sampling_params = _build_video_sampling_params(request_id, req)
    except (ValueError, TypeError) as e:
        for td in temp_dirs:

View on GitHub (pinned to 0132848349)

Solutions

  1. Validate the payload against the VideoGenerationsRequest schema before sending (required fields: model, prompt; check types for size/duration/input_reference)
  2. Inspect the detail string — it embeds the original Pydantic/validation error which names the offending field
  3. If using input_reference images, verify the image source is a valid URL/base64/data path
  4. Check the server logs for the full exception traceback if the detail message is truncated

Example fix

// before
curl -X POST http://localhost:30000/v1/videos -d '{"model": "video-model", "prompt": null}'
// after
curl -X POST http://localhost:30000/v1/videos -H 'Content-Type: application/json' -d '{"model": "video-model", "prompt": "a cat surfing"}'
Defensive patterns

Strategy: validation

Validate before calling

import json
required = {"model", "prompt"}
body = {...}
assert required <= set(body), f'missing: {required - set(body)}'
assert isinstance(body["prompt"], str) and body["prompt"]
json.dumps(body)  # serializable & valid JSON

Type guard

function isVideoRequestBody(b: unknown): b is VideoGenerationsRequest {
  const o = b as any;
  return !!o && typeof o.model === 'string' && typeof o.prompt === 'string' && o.prompt.length > 0;
}

Try / catch

try { await client.post('/v1/videos', body); } catch (e) { if (e.status === 400) throw new Error(`Bad video request: ${e.detail}`); throw e; }

Prevention

When it happens

Trigger: POST /v1/videos with malformed JSON, missing required fields (e.g. model or prompt), wrong types for fields like size/duration, an unparsable input_reference payload, or an image source that fails processing so VideoGenerationsRequest(**payload) or the earlier body-parsing step throws.

Common situations: Cutting-and-pasting curl/JS examples from a different API version where field names changed; sending base64 image data with an unsupported format; omitting newly-required fields after upgrading SGLang; sending null for a required field.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/64f014dbd3a45b5f. Report an issue: GitHub.