{"record":{"id":"06415521b60d4ac8","repo":"ZhuLinsen/daily_stock_analysis","slug":"vision-api-litellm-model-api-key","errorCode":null,"errorMessage":"未配置 Vision API。请设置 LITELLM_MODEL 或相关 API Key。","messagePattern":"未配置 Vision API。请设置 LITELLM_MODEL 或相关 API Key。","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"src/services/image_stock_extractor.py","lineNumber":276,"sourceCode":"\n\ndef _deployment_allows_empty_api_key(deployment: Dict[str, Any]) -> bool:\n    \"\"\"Return whether a configured vision deployment is a supported keyless endpoint.\"\"\"\n    params = deployment.get(\"litellm_params\") or {}\n    if str(params.get(\"api_key\") or \"\").strip():\n        return False\n    wire_model = str(params.get(\"model\") or \"\").strip()\n    protocol = wire_model.split(\"/\", 1)[0] if \"/\" in wire_model else None\n    return channel_allows_empty_api_key(protocol, params.get(\"api_base\"))\n\n\ndef _call_litellm_vision(image_b64: str, mime_type: str, api_key: Optional[str] = None) -> str:\n    \"\"\"Extract stock codes from an image using litellm (all providers via OpenAI vision format).\"\"\"\n    global litellm\n    cfg = get_config()\n    model = _resolve_vision_model()\n    if not model:\n        raise ValueError(\"未配置 Vision API。请设置 LITELLM_MODEL 或相关 API Key。\")\n    if route_has_hermes(getattr(cfg, \"llm_model_list\", []) or [], model):\n        raise ValueError(\"Hermes Vision 未验证：VISION_MODEL 不能选择包含 Hermes deployment 的 route。\")\n\n    deployments = _matching_vision_deployments(model, cfg)\n    keys = _get_api_keys_for_model(model, cfg)\n    key = api_key if api_key and api_key in keys else (random.choice(keys) if keys else None)\n\n    deployment_params: Dict[str, Any] = {}\n    if deployments:\n        deployment = next(\n            (\n                item\n                for item in deployments\n                if str((item.get(\"litellm_params\") or {}).get(\"api_key\") or \"\").strip() == key\n            ),\n            None,\n        )\n        if deployment is None:","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/src/services/image_stock_extractor.py#L258-L294","documentation":"Error \"未配置 Vision API。请设置 LITELLM_MODEL 或相关 API Key。\" thrown in ZhuLinsen/daily_stock_analysis.","triggerScenarios":"Thrown at src/services/image_stock_extractor.py:276 when the library encounters an invalid state.","commonSituations":"Raised when no vision-capable model is configured for image extraction; occurs when LITELLM_MODEL and related API keys are unset while using image import.","solutions":["Set LITELLM_MODEL and the corresponding API key (e.g. OPENAI_API_KEY, GEMINI_API_KEY) in .env to enable the Vision API.","Choose a vision-capable model and configure its credentials.","Restart the service after updating the environment configuration."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}