sgl-project/sglang · error · ValueError
Model is required
Error message
Model is required
What it means
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.
Source
Thrown at python/sglang/srt/entrypoints/anthropic/protocol.py:386
stop_sequences: Optional[list[str]] = None
stream: Optional[bool] = False
system: Optional[Union[str, list[AnthropicContentBlock]]] = None
temperature: Optional[float] = None
thinking: Optional[AnthropicThinkingParam] = None
tool_choice: Optional[AnthropicToolChoice] = None
tools: Optional[list[AnthropicTool]] = None
top_k: Optional[int] = None
top_p: Optional[float] = None
# Claude 4.7 fields. The Anthropic SDK / Claude Code attach these even
# when targeting non-Anthropic backends, so the schema must accept them.
output_config: Optional[AnthropicOutputConfig] = None
betas: Optional[list[str]] = None
@field_validator("model")
@classmethod
def _validate_model(cls, v):
if not v:
raise ValueError("Model is required")
return v
@field_validator("max_tokens")
@classmethod
def _validate_max_tokens(cls, v):
if v <= 0:
raise ValueError("max_tokens must be positive")
return v
# ---------- Stream deltas ----------
# Content-block deltas (discriminated by ``type``) vs message-end delta
# (separate model; the wire format does not put ``type`` inside its payload).
class TextDelta(BaseModel):
type: Literal["text_delta"] = "text_delta"
text: strView on GitHub (pinned to 0132848349)
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
Example fix
// before
{"model": "", "messages": [...]}
// after
{"model": "my-model", "messages": [...]} Defensive patterns
Strategy: validation
Validate before calling
if not model or not model.strip():
raise ValueError("model must be a non-empty string") Type guard
def is_valid_model(m: object) -> bool:
return isinstance(m, str) and len(m.strip()) > 0 Prevention
- Resolve model from env with a fail-fast default check at startup
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.
Related errors
- thinking.budget_tokens must be >= 1024 (got {})
- thinking.budget_tokens is not allowed when thinking.type is
- thinking.display is not allowed when thinking.type is 'disab
- thinking.budget_tokens is not allowed when thinking.type is
- max_tokens must be positive
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/db1b4c5a9d44e089.
Report an issue: GitHub.