{"record":{"id":"50f1327790043aa6","repo":"harry0703/MoneyPrinterTurbo","slug":"llm-provider-returned-an-error-response-res","errorCode":null,"errorMessage":"[{llm_provider}] returned an error response: \"{response}\"","messagePattern":"\\[(.+?)\\] returned an error response: \"(.+?)\"","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"app/services/llm.py","lineNumber":228,"sourceCode":"            if field.required and not extra_values[field.config_suffix]:\n                raise ValueError(\n                    f\"{llm_provider}: {field.config_suffix} is not set, \"\n                    \"please set it in the config.toml file.\"\n                )\n\n        if adapter == \"qwen\":\n            import dashscope\n            from dashscope.api_entities.dashscope_response import GenerationResponse\n\n            dashscope.api_key = api_key\n            response = dashscope.Generation.call(\n                model=model_name, messages=[{\"role\": \"user\", \"content\": prompt}]\n            )\n            if response:\n                if isinstance(response, GenerationResponse):\n                    status_code = response.status_code\n                    if status_code != 200:\n                        raise Exception(\n                            f'[{llm_provider}] returned an error response: \"{response}\"'\n                        )\n\n                    return _extract_qwen_generation_text(response)\n                else:\n                    raise Exception(\n                        f'[{llm_provider}] returned an invalid response: \"{response}\"'\n                    )\n            else:\n                raise Exception(f\"[{llm_provider}] returned an empty response\")\n\n        if adapter == \"gemini\":\n            from google import genai\n            from google.genai import types\n\n            http_options = types.HttpOptions(base_url=base_url) if base_url else None\n            generation_config = types.GenerateContentConfig(\n                temperature=0.5,","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/harry0703/MoneyPrinterTurbo/blob/1f9f19c2021a68d04df228f33e9099a0c947f6f8/app/services/llm.py#L210-L246","documentation":"Raised in the qwen adapter branch of _generate_response() after dashscope.Generation.call() returns a GenerationResponse whose status_code is not 200. Dashscope does not raise on API errors; it packs the HTTP status and code/message into the response object, so this check is the only error surfacing. The full response object is embedded in the message for diagnosis.","triggerScenarios":"dashscope.Generation.call(model=..., messages=[...]) returning status_code 400/401/403/429/500 — e.g. invalid DASHSCOPE API key (401 InvalidApiKey), rate limiting (429 Throttling), nonexistent model_name, or DashScope service outage; also SDK-level errors reported through the response envelope.","commonSituations":"Expired or mistyped qwen api_key in config.toml; using a model name not available to the account's region; hitting free-tier QPS limits during batch video generation; dashscope SDK version drift changing status_code semantics; mainland vs international DashScope endpoint mismatch.","solutions":["Inspect the embedded response: response.code and response.message inside the f-string identify the exact DashScope error (InvalidApiKey, Throttling, InvalidParameter, etc.)","For 401/403 fix [qwen].api_key in config.toml (or set it via WebUI) and re-run test_connection()","For 429 throttle, slow down generation requests or upgrade the DashScope quota tier","For invalid model errors, set [qwen].model_name to a currently valid model (e.g. qwen-turbo/qwen-plus) and upgrade the dashscope package","For 5xx or intermittent SDK errors, retry — the caller already wraps this in a retry loop (_max_retries = 5) so repeated failures indicate a persistent issue"],"exampleFix":"# before\nresponse = dashscope.Generation.call(\n    model=model_name, messages=[{\"role\": \"user\", \"content\": prompt}]\n)\nif status_code != 200:\n    raise Exception(f'[{llm_provider}] returned an error response: \"{response}\"')\n\n# after (log the structured fields instead of the whole object)\nif status_code != 200:\n    raise Exception(\n        f\"[qwen] API error {status_code}: {response.code} - {response.message}\"\n    )","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"except Exception as e: — inspect the embedded DashScope code; retry only on 429/5xx-type codes (Throttling, ServiceUnavailable), fail fast on 401/403 (InvalidApiKey) since retries cannot fix credentials","preventionTips":["Keep the qwen api_key valid and rotate before expiry","Batch generation jobs with pacing to stay under DashScope QPS limits","Log response.code/response.message separately so failures are triageable without the full response dump"],"tags":["llm","qwen","dashscope","api-error","network"],"backgroundTag":null,"analyzedSha":"1f9f19c2021a68d04df228f33e9099a0c947f6f8","analyzedAt":"2026-08-14T19:41:05.568Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}