{"record":{"id":"892e64c4374d4f0d","repo":"ATH-MaaS/Pixelle-Video","slug":"str-e-892e64","errorCode":null,"errorMessage":"str(e)","messagePattern":"str\\(e\\)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"api/routers/llm.py","lineNumber":59,"sourceCode":"    \"\"\"\n    try:\n        logger.info(f\"LLM chat request: {request.prompt[:50]}...\")\n        \n        # Call LLM service\n        response = await pixelle_video.llm(\n            prompt=request.prompt,\n            temperature=request.temperature,\n            max_tokens=request.max_tokens\n        )\n        \n        return LLMChatResponse(\n            content=response,\n            tokens_used=None  # Can add token counting if needed\n        )\n        \n    except Exception as e:\n        logger.error(f\"LLM chat error: {e}\")\n        raise HTTPException(status_code=500, detail=str(e))\n\n","sourceCodeStart":41,"sourceCodeEnd":61,"githubUrl":"https://github.com/ATH-MaaS/Pixelle-Video/blob/848b054e4fae40dabc62ec58e960b573e83793ac/api/routers/llm.py#L41-L61","documentation":"The LLM chat endpoint catches every exception from the chat call and re-raises it as HTTP 500 with str(e) as detail. This means the LLM provider call (or response handling) failed after the request passed validation. The raw internal error string is leaked to the client.","triggerScenarios":"POST chat request where the LLM client throws: missing/invalid API key, provider network error, rate limit, model name not found, quota exhausted, or malformed provider response.","commonSituations":"LLM provider API key not configured or expired in env; wrong model name after provider deprecated it; provider outage or 429 rate limiting; no network egress from the server to the provider.","solutions":["Check server logs for 'LLM chat error:' to see the underlying provider error","Verify the LLM provider API key/env vars are set and valid","Confirm the requested model name is still available from the provider","Retry with backoff if the error was a transient network/429 failure","Server-side: map provider errors to 4xx/502 with sanitized detail instead of str(e)"],"exampleFix":"// before\nexcept Exception as e:\n    logger.error(f\"LLM chat error: {e}\")\n    raise HTTPException(status_code=500, detail=str(e))\n// after\nexcept Exception:\n    logger.exception(\"LLM chat error\")\n    raise HTTPException(status_code=502, detail=\"LLM provider request failed; check configuration\")","handlingStrategy":"try-catch","validationCode":"// fail fast if LLM provider env is not configured (server operator check)\nimport os\nassert os.getenv(\"LLM_API_KEY\"), \"LLM_API_KEY not set\"\nassert os.getenv(\"LLM_MODEL\"), \"LLM_MODEL not set\"","typeGuard":"function isLLMChatResponse(r) { return r != null && typeof r.content === 'string'; }","tryCatchPattern":"try {\n  const res = await fetch('/chat', {method:'POST', body: JSON.stringify({messages})});\n  if (!res.ok) {\n    const {detail} = await res.json().catch(() => ({}));\n    throw new Error(detail || `LLM chat failed (${res.status})`);\n  }\n  return await res.json();\n} catch (err) {\n  // retry once on transient errors, then degrade to a fallback model or message\n}","preventionTips":["Set and rotate the LLM provider API key before deploying","Pin a currently-supported model name; provider deprecations cause hard failures","Add retry with backoff for 429/network errors","Monitor provider status pages and set alerts on 5xx chat rates"],"tags":["http-500","llm","api-key","provider-error"],"backgroundTag":"llm-provider-request-failed","analyzedSha":"848b054e4fae40dabc62ec58e960b573e83793ac","analyzedAt":"2026-08-30T03:24:41.468Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}