{"record":{"id":"a41ee3faf6b11b95","repo":"FoundationAgents/MetaGPT","slug":"model-is-required","errorCode":null,"errorMessage":"Model is required!","messagePattern":"Model is required!","errorType":"validation","errorClass":"ModelRequired","httpStatus":null,"severity":"error","filePath":"metagpt/provider/dashscope_api.py","lineNumber":122,"sourceCode":"    return request\n\n\nclass AGeneration(Generation, BaseAioApi):\n    @classmethod\n    async def acall(\n        cls,\n        model: str,\n        prompt: Any = None,\n        history: list = None,\n        api_key: str = None,\n        messages: List[Message] = None,\n        plugins: Union[str, Dict[str, Any]] = None,\n        **kwargs,\n    ) -> Union[GenerationResponse, AsyncGenerator[GenerationResponse, None]]:\n        if (prompt is None or not prompt) and (messages is None or not messages):\n            raise InputRequired(\"prompt or messages is required!\")\n        if model is None or not model:\n            raise ModelRequired(\"Model is required!\")\n        task_group, function = \"aigc\", \"generation\"  # fixed value\n        if plugins is not None:\n            headers = kwargs.pop(\"headers\", {})\n            if isinstance(plugins, str):\n                headers[\"X-DashScope-Plugin\"] = plugins\n            else:\n                headers[\"X-DashScope-Plugin\"] = json.dumps(plugins)\n            kwargs[\"headers\"] = headers\n        input, parameters = cls._build_input_parameters(model, prompt, history, messages, **kwargs)\n\n        api_key, model = BaseAioApi._validate_params(api_key, model)\n        request = build_api_arequest(\n            model=model,\n            input=input,\n            task_group=task_group,\n            task=Generation.task,\n            function=function,\n            api_key=api_key,","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/provider/dashscope_api.py#L104-L140","documentation":"Companion guard in DashScope Generation.acall: after the prompt/messages check, a falsy model (None or '') raises ModelRequired('Model is required!'). The model positional must be a non-empty string naming a DashScope model.","triggerScenarios":"Calling Generation.acall(model=None) or model=''; commonly when model is read from config/env and the key is missing, defaulting to None.","commonSituations":"Config-driven model names with a typo'd env var; version upgrades renaming model fields; failing to set the model in the dashscope LLM provider config.","solutions":["Pass an explicit model id, e.g. 'qwen-max', 'qwen-plus', 'qwen-turbo'.","Validate/fail fast at startup that the configured model name is non-empty.","Check the provider config (models.yaml dashscope entry) has its model field set."],"exampleFix":"// before\nresp = await Generation.acall(model=os.getenv(\"DS_MODEL\"), prompt=\"hi\")  # None if unset\n\n// after\nmodel = os.environ[\"DS_MODEL\"]  # fail fast if missing\nresp = await Generation.acall(model=model, prompt=\"hi\")","handlingStrategy":"validation","validationCode":"def model_ok(model) -> bool:\n    return isinstance(model, str) and bool(model.strip())\n\nassert model_ok(cfg_model), f\"model must be a non-empty string, got {cfg_model!r}\"","typeGuard":"def is_nonempty_model_str(m: object) -> bool:\n    return isinstance(m, str) and len(m.strip()) > 0","tryCatchPattern":"try:\n    resp = await Generation.acall(model=model, prompt=prompt)\nexcept Exception as e:\n    if \"Model is required\" in str(e):\n        raise ValueError(f\"model unset; check env/config (got {model!r})\") from e\n    raise","preventionTips":["Fail fast at startup when a required model env var is missing.","Use os.environ[...] (KeyError) instead of os.getenv(...) for mandatory values."],"tags":["dashscope","validation","model-required"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}