POST /api/email/generate
Enqueue a background task to generate a personalized email using the multi-step AI pipeline. This endpoint returns immediately with a task ID for status polling.Email generation typically takes 10-30 seconds depending on web scraping and AI processing time.
Authentication
Requires valid JWT token from Supabase Auth in theAuthorization header.
Request Body
Email template with placeholders for personalization. Must be 10-5000 characters and contain placeholder syntax (e.g.,
{{name}}, {{research}}).Full name of the email recipient (e.g., “Dr. Jane Smith”). Must be 2-255 characters.
Research area or interest for personalization (e.g., “machine learning for healthcare”). Must be 2-500 characters.
Request Example
Response
Celery task ID for polling generation status via GET
/api/email/status/{task_id}Response Example
Status Code
202 Accepted - Task has been queued successfullyError Responses
401 Unauthorized
Invalid or missing JWT token
422 Validation Error
Invalid request parameters (template too short/long, missing fields, etc.)
GET /api/email/status/
Check the status of an asynchronous email generation task. Poll this endpoint every 2 seconds until status is SUCCESS or FAILURE.Authentication
Requires valid JWT token from Supabase Auth in theAuthorization header.
Path Parameters
The Celery task ID returned from POST
/api/email/generateRequest Example
Response
The task ID being queried
Current task state:
PENDING, STARTED, SUCCESS, or FAILURETask result data. Contains different information based on status:
- SUCCESS: Contains
email_idand generation metadata - STARTED: Contains
current_stepand progress information - PENDING/FAILURE: null
Error details if status is FAILURE. Can be a string or structured error object with
message, type, and failed_step.Response Examples
Task Queued (PENDING)Error Responses
401 Unauthorized
Invalid or missing JWT token
404 Not Found
Task ID not found or result expired (>1 hour old)
GET /api/email/
Retrieve a generated email by its ID. Only the email owner can access their emails.Authentication
Requires valid JWT token from Supabase Auth in theAuthorization header.
Path Parameters
The unique identifier of the email to retrieve
Request Example
Response
Email’s unique identifier
ID of the user who generated this email
Name of the email recipient
Research interest used for personalization
The generated email content (full text)
Template type detected by the AI:
research, book, or generalGeneration metadata including:
papers_used: Array of academic papers referenced (for research emails)sources: Array of URLs scrapedgeneration_time: Total time in secondsstep_timings: Time spent in each pipeline step
Whether the AI had sufficient context for high-quality personalization
Whether this email is visible in the user’s history (false = discarded)
Timestamp when email was generated
Response Example
Error Responses
400 Bad Request
Invalid email ID format (not a valid UUID)
401 Unauthorized
Invalid or missing JWT token
404 Not Found
Email not found or user doesn’t have permission to access it
GET /api/email/
Get the user’s email generation history, paginated and sorted by newest first.Authentication
Requires valid JWT token from Supabase Auth in theAuthorization header.
Query Parameters
Maximum number of emails to return (1-100)
Number of emails to skip for pagination
Include emails marked as discarded (displayed=false) in results
Request Example
Response
Returns an array ofEmailResponse objects (same schema as GET /api/email/{email_id}).
Response Example
Error Responses
401 Unauthorized
Invalid or missing JWT token
422 Validation Error
Invalid query parameters (e.g., limit > 100)
PATCH /api/email/
Update email properties. Currently supports updating thedisplayed field to hide/show emails in history (soft delete).
Authentication
Requires valid JWT token from Supabase Auth in theAuthorization header.
Path Parameters
The unique identifier of the email to update
Request Body
Whether to display the email in history:
true: Show in email historyfalse: Hide from email history (soft delete)
Request Example
Response
Returns the updatedEmailResponse object.
Response Example
Error Responses
400 Bad Request
Invalid email ID format (not a valid UUID)
401 Unauthorized
Invalid or missing JWT token
404 Not Found
Email not found or user doesn’t have permission to access it
422 Validation Error
Invalid request body (missing or invalid
displayed field)