{"record":{"id":"b73b8e011a0cfce9","repo":"FoundationAgents/MetaGPT","slug":"please-set-your-api-key-in-repo-config-path","errorCode":null,"errorMessage":"Please set your API key in {repo_config_path}","messagePattern":"Please set your API key in (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"metagpt/configs/llm_config.py","lineNumber":128,"sourceCode":"    use_system_prompt: bool = True\n\n    # reasoning / thinking switch\n    reasoning: bool = False\n    reasoning_max_token: int = 4000  # reasoning budget tokens to generate, usually smaller than max_token\n\n    @field_validator(\"api_key\")\n    @classmethod\n    def check_llm_key(cls, v):\n        if v in [\"\", None, \"YOUR_API_KEY\"]:\n            repo_config_path = METAGPT_ROOT / \"config/config2.yaml\"\n            root_config_path = CONFIG_ROOT / \"config2.yaml\"\n            if root_config_path.exists():\n                raise ValueError(\n                    f\"Please set your API key in {root_config_path}. If you also set your config in {repo_config_path}, \\n\"\n                    f\"the former will overwrite the latter. This may cause unexpected result.\\n\"\n                )\n            elif repo_config_path.exists():\n                raise ValueError(f\"Please set your API key in {repo_config_path}\")\n            else:\n                raise ValueError(\"Please set your API key in config2.yaml\")\n        return v\n\n    @field_validator(\"timeout\")\n    @classmethod\n    def check_timeout(cls, v):\n        return v or LLM_API_TIMEOUT\n","sourceCodeStart":110,"sourceCodeEnd":137,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/configs/llm_config.py#L110-L137","documentation":"Same api_key validator in LLMConfig, but this branch means: no root-level config2.yaml exists, and the repository-local METAGPT_ROOT/config/config2.yaml exists yet its api_key is still empty/placeholder. The value must be set in that repo file specifically.","triggerScenarios":"Instantiating LLM or any LLM-dependent Action when only metagpt's repo config/config2.yaml is present (no ~/.metagpt config) and its api_key is '' / 'YOUR_API_KEY' / unset.","commonSituations":"Fresh clone of MetaGPT used in-place; CI environments that mount the repo but never write a user config; the template file copied unmodified.","solutions":["Edit METAGPT_ROOT/config/config2.yaml and fill api_key for your provider.","Or create a root-level config (~/.metagpt/config2.yaml) with a valid key, which then takes precedence.","Or pass LLMConfig(api_key=...) explicitly in code / export the provider's env key and load config from env."],"exampleFix":"# before (metagpt/config/config2.yaml)\nopenai:\n  api_key: ''\n\n# after\nopenai:\n  api_key: 'sk-...'","handlingStrategy":"validation","validationCode":"import yaml\ncfgp = Path('metagpt/config/config2.yaml')\nif cfgp.exists():\n    data = yaml.safe_load(cfgp.read_text())\n    key = (data.get('openai') or {}).get('api_key')\n    assert key not in ('', None, 'YOUR_API_KEY'), 'repo config2.yaml needs a real api_key'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Edit the repo-level config2.yaml when no root config exists.","Do not ship the template with placeholder keys into runtime images.","Prefer explicit LLMConfig(api_key=...) from a secret manager in production."],"tags":["config","api-key","llm","setup"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}