POST /api/templates/
Generate an email template from a resume PDF using AI. This endpoint is synchronous and typically takes 5-15 seconds. Uses Claude Haiku 4.5 for cost-effective generation.Authentication
Requires valid JWT token from Supabase Auth in theAuthorization header.
Request Body
Public URL to the resume PDF file. Must be a valid HTTPS URL pointing to a publicly accessible PDF file (typically from Supabase Storage).
User guidance for template generation including desired tone, style, length, and focus areas. Must be 10-2000 characters.
Request Example
Response
Template’s unique identifier
ID of the user who created this template
The resume PDF URL used for generation
The generated email template with placeholders like
{{professor_name}}, {{research_area}}, etc.The instructions provided for generation
Timestamp when template was created
Response Example
Status Code
201 Created - Template generated and saved successfullyGeneration Process
- Limit Check: Verifies user hasn’t exceeded 5 templates
- PDF Extraction: Downloads PDF and extracts text content
- AI Generation: Sends resume text + instructions to Claude Haiku 4.5
- Database Save: Stores template and increments user’s template_count
- Response: Returns complete template object
Template Placeholders
The AI typically generates templates with these common placeholders:{{professor_name}}or{{name}}: Recipient’s name{{research_area}}or{{research}}: Research interest{{university}}: Institution name{{paper_title}}: Specific paper or publication{{relevant_topic}}: Contextual topic from research
/api/email/generate or POST /api/queue/batch.
Error Responses
400 Bad Request
PDF parsing or validation errorsCommon causes:
- Invalid or inaccessible PDF URL
- PDF file is corrupted or password-protected
- PDF contains no extractable text (scanned images only)
- Invalid HTTPS certificate
401 Unauthorized
Invalid or missing JWT token
422 Validation Error
Invalid request parameters
429 Too Many Requests
User has exceeded the 5 templates per account limit
500 Internal Server Error
AI generation or system errorsCommon causes:
- Claude API timeout or rate limit
- Database connection issues
- Unexpected AI response format
GET /api/templates/
List all templates created by the current user, paginated and sorted by newest first.Authentication
Requires valid JWT token from Supabase Auth in theAuthorization header.
Query Parameters
Maximum number of templates to return (1-100)
Number of templates to skip for pagination
Request Example
Response
Returns an array ofTemplateResponse objects (same schema as POST /api/templates/).
Response Example
Error Responses
401 Unauthorized
Invalid or missing JWT token
422 Validation Error
Invalid query parameters (e.g., limit > 100)
GET /api/templates/
Retrieve a specific template by its ID. Only the template owner can access their templates.Authentication
Requires valid JWT token from Supabase Auth in theAuthorization header.
Path Parameters
The unique identifier of the template to retrieve
Request Example
Response
Returns a singleTemplateResponse object.
Response Example
Error Responses
400 Bad Request
Invalid template ID format (not a valid UUID)
401 Unauthorized
Invalid or missing JWT token
404 Not Found
Template not found or user doesn’t have permission to access it
Template Generation Details
AI Model Configuration
- Model: Claude Haiku 4.5 (
claude-haiku-4.5-20241022) - Provider: Anthropic API
- Max Tokens: 4096
- Temperature: 0.7 (balanced creativity)
- Timeout: 45 seconds per request
- Retries: 3 attempts with exponential backoff
PDF Text Extraction
The system usespypdf library to extract text from PDF files:
- Download: Fetches PDF from provided URL
- Validation: Ensures file is valid PDF format
- Extraction: Extracts all text content from all pages
- Sanitization: Removes excessive whitespace and formatting artifacts
- AI Prompt: Combines resume text with user instructions
Supported PDF Features
- Text-based PDFs: Fully supported
- Scanned PDFs: Not supported (no OCR)
- Password-protected PDFs: Not supported
- Multi-page PDFs: Supported (all pages extracted)
- Embedded images: Ignored (text only)
Template Quality Tips
Rate Limits
- Per User: Maximum 5 templates per account (lifetime)
- Per Request: 45 second timeout for AI generation
- API Quota: Subject to Anthropic API rate limits (handled with retries)
Storage and Persistence
Templates are stored permanently in the PostgreSQL database:- No automatic deletion
- Cascade delete when user account is deleted
- No size limits on template text (PostgreSQL TEXT field)
- PDF URLs stored as-is (not downloaded/cached)
