{"record":{"id":"be765d804953d75f","repo":"hsliuping/TradingAgents-CN","slug":"provider-name-default-base-u","errorCode":null,"errorMessage":"使用自定义厂家 {provider_name} 需要在数据库配置中设置 default_base_url","messagePattern":"使用自定义厂家 (.+?) 需要在数据库配置中设置 default_base_url","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"tradingagents/graph/trading_graph.py","lineNumber":536,"sourceCode":"\n            custom_api_key = None\n            for env_var in api_key_candidates:\n                custom_api_key = os.getenv(env_var)\n                if custom_api_key:\n                    logger.info(f\"✅ 从环境变量 {env_var} 获取到 API Key\")\n                    break\n\n            if not custom_api_key:\n                raise ValueError(\n                    f\"使用自定义厂家 {provider_name} 需要设置以下环境变量之一:\\n\"\n                    f\"  - {provider_name.upper()}_API_KEY\\n\"\n                    f\"  - CUSTOM_OPENAI_API_KEY\"\n                )\n\n            # 获取 backend_url（从配置中获取）\n            backend_url = self.config.get(\"backend_url\")\n            if not backend_url:\n                raise ValueError(\n                    f\"使用自定义厂家 {provider_name} 需要在数据库配置中设置 default_base_url\"\n                )\n\n            logger.info(f\"🔧 [自定义厂家 {provider_name}] 使用端点: {backend_url}\")\n\n            # 🔧 从配置中读取模型参数\n            quick_config = self.config.get(\"quick_model_config\", {})\n            deep_config = self.config.get(\"deep_model_config\", {})\n\n            quick_max_tokens = quick_config.get(\"max_tokens\", 4000)\n            quick_temperature = quick_config.get(\"temperature\", 0.7)\n            quick_timeout = quick_config.get(\"timeout\", 180)\n\n            deep_max_tokens = deep_config.get(\"max_tokens\", 4000)\n            deep_temperature = deep_config.get(\"temperature\", 0.7)\n            deep_timeout = deep_config.get(\"timeout\", 180)\n\n            logger.info(f\"🔧 [{provider_name}-快速模型] max_tokens={quick_max_tokens}, temperature={quick_temperature}, timeout={quick_timeout}s\")","sourceCodeStart":518,"sourceCodeEnd":554,"githubUrl":"https://github.com/hsliuping/TradingAgents-CN/blob/74783e8817d6cf6de29867880631cc555153f36b/tradingagents/graph/trading_graph.py#L518-L554","documentation":"TradingAgentsGraph.__init__ raises this for custom providers when the env-var key check passed but config['backend_url'] is empty. Custom providers have no built-in default endpoint, so the OpenAI-compatible base URL must be supplied via configuration. Thrown right after key resolution, before client construction.","triggerScenarios":"Custom provider with API key set via env but no backend_url/default_base_url stored in config (e.g. provider record created in web UI without filling the endpoint field).","commonSituations":"Provider record partially configured — key filled, URL left blank; config dict built manually and backend_url key omitted; URL stored under a different key name (e.g. base_url) that this branch ignores.","solutions":["Set backend_url in the provider config (web UI field default_base_url, or config dict key 'backend_url') to e.g. https://api.myllm.com/v1","Verify the value survives config merging/print config.get('backend_url') before graph init","For scripts, pass config={..., 'backend_url': 'https://...'} explicitly"],"exampleFix":"# before\ncfg = {\"llm_provider\": \"myllm\"}  # no backend_url\ngraph = TradingAgentsGraph(config=cfg)\n\n# after\ncfg = {\"llm_provider\": \"myllm\", \"backend_url\": \"https://api.myllm.com/v1\"}\ngraph = TradingAgentsGraph(config=cfg)","handlingStrategy":"validation","validationCode":"if provider_is_custom and not cfg.get(\"backend_url\"):\n    raise SystemExit(\"Custom providers require backend_url/default_base_url in config\")","typeGuard":"def custom_provider_config_complete(cfg: dict) -> bool:\n    return bool(cfg.get(\"backend_url\"))","tryCatchPattern":"try:\n    graph = TradingAgentsGraph(config=cfg)\nexcept ValueError as e:\n    if \"default_base_url\" in str(e):\n        cfg[\"backend_url\"] = \"https://api.default.example/v1\"  # known fallback\n        graph = TradingAgentsGraph(config=cfg)\n    else:\n        raise","preventionTips":["Make provider creation forms require the base URL field","Store endpoint under the exact key 'backend_url'","Validate custom provider records (key + URL) before saving config"],"tags":["configuration","missing-base-url","custom-provider","openai-compatible"],"backgroundTag":"missing-base-url","analyzedSha":"74783e8817d6cf6de29867880631cc555153f36b","analyzedAt":"2026-08-28T11:39:07.729Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}