{"record":{"id":"db1b4c5a9d44e089","repo":"sgl-project/sglang","slug":"model-is-required","errorCode":null,"errorMessage":"Model is required","messagePattern":"Model is required","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"python/sglang/srt/entrypoints/anthropic/protocol.py","lineNumber":386,"sourceCode":"    stop_sequences: Optional[list[str]] = None\n    stream: Optional[bool] = False\n    system: Optional[Union[str, list[AnthropicContentBlock]]] = None\n    temperature: Optional[float] = None\n    thinking: Optional[AnthropicThinkingParam] = None\n    tool_choice: Optional[AnthropicToolChoice] = None\n    tools: Optional[list[AnthropicTool]] = None\n    top_k: Optional[int] = None\n    top_p: Optional[float] = None\n    # Claude 4.7 fields. The Anthropic SDK / Claude Code attach these even\n    # when targeting non-Anthropic backends, so the schema must accept them.\n    output_config: Optional[AnthropicOutputConfig] = None\n    betas: Optional[list[str]] = None\n\n    @field_validator(\"model\")\n    @classmethod\n    def _validate_model(cls, v):\n        if not v:\n            raise ValueError(\"Model is required\")\n        return v\n\n    @field_validator(\"max_tokens\")\n    @classmethod\n    def _validate_max_tokens(cls, v):\n        if v <= 0:\n            raise ValueError(\"max_tokens must be positive\")\n        return v\n\n\n# ---------- Stream deltas ----------\n# Content-block deltas (discriminated by ``type``) vs message-end delta\n# (separate model; the wire format does not put ``type`` inside its payload).\n\n\nclass TextDelta(BaseModel):\n    type: Literal[\"text_delta\"] = \"text_delta\"\n    text: str","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/entrypoints/anthropic/protocol.py#L368-L404","documentation":"Raised by the pydantic field validator on the MessagesRequest model when the model field is empty or missing after parsing. The Anthropic-compatible endpoint requires a model identifier to route the request, so an empty string or null model is rejected with a 400.","triggerScenarios":"POST /v1/messages with model: \"\" or omitting the model field (if the client schema allows), or a client that substitutes an empty model env var.","commonSituations":"Model name read from an unset environment variable or config key; templating that renders an empty model placeholder; proxy stripping the model field before forwarding.","solutions":["Set model to a deployed model name, e.g. the --model-path the server was launched with","Check the client's model configuration/env vars resolve to a non-empty string","Verify the request body actually includes the model field"],"exampleFix":"// before\n{\"model\": \"\", \"messages\": [...]}\n// after\n{\"model\": \"my-model\", \"messages\": [...]}","handlingStrategy":"validation","validationCode":"if not model or not model.strip():\n    raise ValueError(\"model must be a non-empty string\")","typeGuard":"def is_valid_model(m: object) -> bool:\n    return isinstance(m, str) and len(m.strip()) > 0","tryCatchPattern":null,"preventionTips":["Resolve model from env with a fail-fast default check at startup"],"tags":["anthropic","model","validation","request-validation","missing-field"],"backgroundTag":"missing-required-field","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}