diff --git a/api/routes/legal_aid.py b/api/routes/legal_aid.py index 487471c..bbb594c 100644 --- a/api/routes/legal_aid.py +++ b/api/routes/legal_aid.py @@ -123,8 +123,12 @@ async def parse_pdf_report( page_count = min(len(doc), _PDF_MAX_PAGES) for i in range(page_count): pix = doc[i].get_pixmap(dpi=_PDF_RENDER_DPI) - png = pix.tobytes("png") - images_b64.append(("image/png", base64.b64encode(png).decode("ascii"))) + # JPEG (not PNG): a rendered table page is mostly white, and + # PNG of it is several × larger than a q85 JPEG. Bundling all + # pages as PNG blew past ai-gateway's body limit (413). JPEG + # q85 keeps the table text crisp enough for Claude Vision. + jpg = pix.tobytes("jpeg", jpg_quality=85) + images_b64.append(("image/jpeg", base64.b64encode(jpg).decode("ascii"))) except Exception as e: logger.exception("Legal Aid PDF render failed") raise HTTPException(status_code=422, detail=f"PDF render error: {e}")