ATH-MaaS/Pixelle-Video · error · HTTPException

str(e)

Error message

str(e)

What it means

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.

Source

Thrown at api/routers/llm.py:59

    """
    try:
        logger.info(f"LLM chat request: {request.prompt[:50]}...")
        
        # Call LLM service
        response = await pixelle_video.llm(
            prompt=request.prompt,
            temperature=request.temperature,
            max_tokens=request.max_tokens
        )
        
        return LLMChatResponse(
            content=response,
            tokens_used=None  # Can add token counting if needed
        )
        
    except Exception as e:
        logger.error(f"LLM chat error: {e}")
        raise HTTPException(status_code=500, detail=str(e))

View on GitHub (pinned to 848b054e4f)

Solutions

  1. Check server logs for 'LLM chat error:' to see the underlying provider error
  2. Verify the LLM provider API key/env vars are set and valid
  3. Confirm the requested model name is still available from the provider
  4. Retry with backoff if the error was a transient network/429 failure
  5. Server-side: map provider errors to 4xx/502 with sanitized detail instead of str(e)

Example fix

// before
except Exception as e:
    logger.error(f"LLM chat error: {e}")
    raise HTTPException(status_code=500, detail=str(e))
// after
except Exception:
    logger.exception("LLM chat error")
    raise HTTPException(status_code=502, detail="LLM provider request failed; check configuration")
Defensive patterns

Strategy: try-catch

Validate before calling

// fail fast if LLM provider env is not configured (server operator check)
import os
assert os.getenv("LLM_API_KEY"), "LLM_API_KEY not set"
assert os.getenv("LLM_MODEL"), "LLM_MODEL not set"

Type guard

function isLLMChatResponse(r) { return r != null && typeof r.content === 'string'; }

Try / catch

try {
  const res = await fetch('/chat', {method:'POST', body: JSON.stringify({messages})});
  if (!res.ok) {
    const {detail} = await res.json().catch(() => ({}));
    throw new Error(detail || `LLM chat failed (${res.status})`);
  }
  return await res.json();
} catch (err) {
  // retry once on transient errors, then degrade to a fallback model or message
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of ATH-MaaS/Pixelle-Video@848b054e4f (2026-08-30). Data as JSON: /api/errors/892e64c4374d4f0d. Report an issue: GitHub.