{"record":{"id":"13242abb3521b66f","repo":"sgl-project/sglang","slug":"runtime-response-format-must-be-envelope-or-raw","errorCode":null,"errorMessage":"runtime.response_format must be 'envelope' or 'raw'","messagePattern":"runtime\\.response_format must be 'envelope' or 'raw'","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/entrypoints/action/api.py","lineNumber":70,"sourceCode":"    \"prompt\",\n    \"reference_url\",\n    \"request_id\",\n    \"task\",\n    \"video_reference\",\n}\n\n\ndef _wants_msgpack(request: Request) -> bool:\n    content_type = request.headers.get(\"content-type\", \"\").lower()\n    accept = request.headers.get(\"accept\", \"\").lower()\n    return \"msgpack\" in content_type or \"msgpack\" in accept\n\n\ndef _response_format(payload: dict) -> str:\n    runtime = payload.get(\"runtime\") or {}\n    response_format = str(runtime.get(\"response_format\", \"envelope\")).lower()\n    if response_format not in (\"envelope\", \"raw\"):\n        raise ValueError(\"runtime.response_format must be 'envelope' or 'raw'\")\n    return response_format\n\n\ndef _prefer_numpy_output(payload: dict) -> None:\n    runtime = payload.setdefault(\"runtime\", {})\n    runtime.setdefault(\"output_format\", \"numpy\")\n\n\ndef _parse_form_value(value: Any) -> Any:\n    if not isinstance(value, str):\n        return value\n    if not value.strip():\n        return None\n    try:\n        return json.loads(value)\n    except Exception:\n        return value\n","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/entrypoints/action/api.py#L52-L88","documentation":"The action API validates payload['runtime']['response_format'] and only accepts 'envelope' or 'raw' (case-insensitive, default 'envelope'). Any other string raises this ValueError, which surfaces as an HTTP 400 from create_action_generation.","triggerScenarios":"POSTing to the action generation endpoint with body {\"runtime\": {\"response_format\": \"json\"}} or 'ENVELOPE ' (trailing space), or misspelling the value.","commonSituations":"Clients guessing the response format option names; copy-paste from a different API version; passing 'msgpack' (which is a separate flag) as response_format.","solutions":["Set runtime.response_format to 'envelope' (default) or 'raw' exactly, lowercased","Omit the field entirely to get the default 'envelope' behavior","Check the endpoint's schema/docs for the accepted enum values"],"exampleFix":"// before\n{\"input\": {...}, \"runtime\": {\"response_format\": \"json\"}}\n\n// after\n{\"input\": {...}, \"runtime\": {\"response_format\": \"raw\"}}","handlingStrategy":"validation","validationCode":"def normalize_response_format(payload):\n    rf = (payload.get(\"runtime\") or {}).get(\"response_format\", \"envelope\")\n    rf = str(rf).strip().lower()\n    assert rf in (\"envelope\", \"raw\"), f\"bad response_format: {rf!r}\"\n    payload.setdefault(\"runtime\", {})[\"response_format\"] = rf\n    return payload","typeGuard":"def is_valid_response_format(v: str) -> bool:\n    return isinstance(v, str) and v.strip().lower() in (\"envelope\", \"raw\")","tryCatchPattern":null,"preventionTips":["Centralize request-building in one client function with enum-constrained fields","Strip/normalize casing before sending","Omit optional fields you don't need"],"tags":["api","request-validation","response-format","http-400"],"backgroundTag":"invalid-request-parameter","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}