{"record":{"id":"cc343ed7f930c9d0","repo":"huggingface/transformers","slug":"missing-model-field-in-the-request-body","errorCode":null,"errorMessage":"Missing `model` field in the request body.","messagePattern":"Missing `model` field in the request body\\.","errorType":"http","errorClass":"HTTPException","httpStatus":422,"severity":"error","filePath":"src/transformers/cli/serving/server.py","lineNumber":125,"sourceCode":"    @app.post(\"/v1/completions\")\n    async def completions(request: Request, body: dict):\n        return await completion_handler.handle_request(body, request.state.request_id)\n\n    @app.post(\"/v1/responses\")\n    async def responses(request: Request, body: dict):\n        return await response_handler.handle_request(body, request.state.request_id)\n\n    @app.post(\"/v1/audio/transcriptions\")\n    async def audio_transcriptions(request: Request):\n        return await transcription_handler.handle_request(request)\n\n    @app.post(\"/load_model\")\n    async def load_model(body: dict):\n        from fastapi import HTTPException\n\n        model = body.get(\"model\")\n        if model is None:\n            raise HTTPException(status_code=422, detail=\"Missing `model` field in the request body.\")\n        model_id_and_revision = model_manager.process_model_name(model)\n        return StreamingResponse(\n            model_manager.load_model_streaming(model_id_and_revision), media_type=\"text/event-stream\"\n        )\n\n    @app.post(\"/reset\")\n    def reset():\n        model_manager.shutdown()\n        return JSONResponse({\"status\": \"ok\"})\n\n    @app.get(\"/v1/models\")\n    @app.options(\"/v1/models\")\n    def list_models():\n        return JSONResponse({\"object\": \"list\", \"data\": model_manager.get_gen_models()})\n\n    @app.get(\"/health\")\n    def health():\n        if not generation_state.is_cb_alive():","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/cli/serving/server.py#L107-L143","documentation":"Raised as an HTTP 422 by the /load_model endpoint of the transformers CLI serving server. The endpoint expects a JSON body such as {\"model\": \"gpt2\"} and refuses to proceed when the 'model' key is absent or null. It exists so clients fail fast with a clear message instead of triggering a KeyError deep inside model loading.","triggerScenarios":"POST /load_model with an empty body, a JSON body lacking the \"model\" key, or \"model\": null. Any HTTP client (curl, requests, fetch) that forgets to serialize the model id into the payload.","commonSituations":"Scripts that build the request body dynamically and skip the model field when a variable is unset; clients assuming the server has a default model; typos like \"model_name\" or \"modelId\" instead of \"model\".","solutions":["Send a JSON body containing the model field: curl -X POST http://host:port/load_model -H 'Content-Type: application/json' -d '{\"model\": \"openai-community/gpt2\"}'","Check that the variable holding the model id is set before building the request body","Verify you are hitting /load_model with POST and a JSON Content-Type, not a form or query string"],"exampleFix":"// before\ncurl -X POST http://localhost:8000/load_model -d '{}'\n// after\ncurl -X POST http://localhost:8000/load_model -H 'Content-Type: application/json' -d '{\"model\": \"openai-community/gpt2\"}'","handlingStrategy":"validation","validationCode":"body = {\"model\": model_id}\nassert isinstance(body.get(\"model\"), str) and body[\"model\"], \"POST /load_model requires a non-empty 'model' string\"","typeGuard":null,"tryCatchPattern":"resp = requests.post(f'{base}/load_model', json=body)\nif resp.status_code == 422 and 'Missing `model` field' in resp.text:\n    raise ValueError('request body must include the model id') from None","preventionTips":["Always build the /load_model body as {'model': model_id} from a validated variable","Log the request body (minus secrets) before sending when debugging 422s"],"tags":["api","serving","validation","http-422"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}