{"record":{"id":"93d9c3d7d4fa8e76","repo":"datawhalechina/hello-agents","slug":"aminer-api-key-https-open-aminer-cn","errorCode":null,"errorMessage":"未配置 AMiner API Key。请前往 https://open.aminer.cn/ 注册获取，然后在 .env 中设置: AMINER_API_KEY=你的key","messagePattern":"未配置 AMiner API Key。请前往 https://open\\.aminer\\.cn/ 注册获取，然后在 \\.env 中设置: AMINER_API_KEY=你的key","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"Co-creation-projects/chengH425-PaperAssistant/src/aminer_tool.py","lineNumber":41,"sourceCode":"    覆盖 3.2 亿+ 论文，是 Semantic Scholar 的中文补充。\n    \"\"\"\n\n    SEARCH_URL = \"https://datacenter.aminer.cn/gateway/open_platform/api/paper/search\"\n\n    def __init__(self):\n        super().__init__(\n            name=\"aminer_search\",\n            description=\"通过 AMiner API 检索中英文学术论文。\"\n                        \"覆盖 3.2 亿+ 论文，擅长中文文献和中文作者搜索。\"\n                        \"当需要检索中文学术论文或中国学者的英文论文时使用此工具。\"\n                        \"需要先注册获取 API Key: https://open.aminer.cn/\"\n        )\n\n    def _get_api_key(self) -> str:\n        \"\"\"获取 AMiner API Key\"\"\"\n        key = os.getenv(\"AMINER_API_KEY\", \"\")\n        if not key:\n            raise RuntimeError(\n                \"未配置 AMiner API Key。请前往 https://open.aminer.cn/ 注册获取，\"\n                \"然后在 .env 中设置: AMINER_API_KEY=你的key\"\n            )\n        return key\n\n    def run(self, parameters: Dict[str, Any]) -> ToolResponse:\n        keyword = parameters.get(\"keyword\", \"\")\n        author = parameters.get(\"author\", \"\")\n        max_results = min(parameters.get(\"max_results\", 5), 20)\n\n        if not keyword and not author:\n            return ToolResponse.error(\n                code=\"INVALID_PARAM\",\n                message=\"请至少提供关键词（keyword）或作者（author）\"\n            )\n\n        # AMiner 用 title 参数做关键词搜索\n        query = keyword or author","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/chengH425-PaperAssistant/src/aminer_tool.py#L23-L59","documentation":"The AMiner search tool (`aminer_search`) raises RuntimeError from `_get_api_key()` when the `AMINER_API_KEY` environment variable is empty or unset. It is a fail-fast configuration guard: the tool refuses to call the AMiner API without credentials and points the user to https://open.aminer.cn/ registration.","triggerScenarios":"Invoking the `aminer_search` tool with `AMINER_API_KEY` unset, set to an empty string, or defined only in a .env file that was never loaded (e.g. server started from a different working directory than the one containing .env).","commonSituations":"Fresh clone without .env setup, .env present but the key line commented out, or deployment environment (Docker/systemd) where .env is not copied in and env vars are not exported.","solutions":["Register at https://open.aminer.cn/ and add `AMINER_API_KEY=<your-key>` to the project's .env.","Restart the server after editing .env so the new environment is picked up.","If running under Docker/systemd, ensure the variable is passed via env_file/environment, not only the local .env.","Verify with `python -c \"import os; print(bool(os.getenv('AMINER_API_KEY')))\"` in the same shell/env as the server."],"exampleFix":"// before\n# .env (missing or empty)\n\n# after\n# .env\nAMINER_API_KEY=your_registered_key_here","handlingStrategy":"validation","validationCode":"import os\n\ndef aminer_ready() -> bool:\n    return bool(os.getenv(\"AMINER_API_KEY\"))\n\nif not aminer_ready():\n    print(\"Set AMINER_API_KEY in .env (register at https://open.aminer.cn/) before using aminer_search\")","typeGuard":null,"tryCatchPattern":"try:\n    result = aminer_tool.run({\"keyword\": \"graph neural networks\"})\nexcept RuntimeError as e:\n    if \"AMINER_API_KEY\" in str(e):\n        disable_tool(\"aminer_search\")  # degrade gracefully, keep other tools usable\n    raise","preventionTips":["Copy .env.example to .env and fill every *_API_KEY at project setup.","Add a startup check that lists which tool API keys are configured.","Run the server from the directory containing .env so dotenv loads it."],"tags":["configuration","env-vars","api-key","aminer","python"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}