Hi @GunaR,
You are right. There is no API endpoint to export an Agent mode response as a PDF. The "Download PDF" button is a UI-only feature. But since the Agent Mode API provides a fully structured response, you can generate the PDF yourself on the client side.
When the SSE stream completes, the response.completed event contains all output items. The final report lives in the message output item. You can also retrieve it after the fact using the List conversation items endpoint:
GET /api/2.0/genie/agents/{agent_id}/conversations/{conversation_id}/items
Loop through the output and grab the message type item, that's your report text.
Once you have the report content, convert it to PDF using a Python library.weasyprint works well for this because the report is essentially markdown that you can render through HTML:
import markdown
from weasyprint import HTML
html = markdown.markdown(report_text, extensions=['tables'])
HTML(string=f"<html><body>{html}</body></html>").write_pdf("report.pdf")
If you want something lighter with no system dependencies, fpdf2 is a good alternative.
From there, attach the generated file and send it using smtplib, SendGrid, or whatever email service you already use.
Just remember that if you set enable_viz: true in your request, the API returns visualisation specs but not rendered images. You would need to render those separately (for example with matplotlib or plotly) before embedding them in the PDF.
Hope this helps.
If this answer resolves your question, could you mark it as โAccept as Solutionโ? That helps other users quickly find the correct fix.
Regards,
Ashwin | Delivery Solution Architect @ Databricks
Helping you build and scale the Data Intelligence Platform.
***Opinions are my own***