Generate Document API
The Generate Document API endpoint allows you to create documents using AI models and templates programmatically.
Endpoint
POST https://api.promptpdf.com/v1/generate
Authentication
This endpoint requires authentication. See the Authentication page for details.
Request Parameters
The request body should be a JSON object with the following parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| prompt | string | Yes | The text prompt describing what you want in the document |
| template | string | No | The template ID to use (default: "blank") |
| modelType | string | No | The AI model to use (default: "qwen") |
| format | string | No | The output format: "pdf", "doc", "csv", or "markdown" (default: "pdf") |
| existingContent | string | No | Existing content to refine (for document refinement) |
| webhook | boolean | No | Whether to use webhooks for notification (default: false) |
| webhookUrl | string | No | Custom webhook URL (overrides the default webhook URL in your settings) |
Available Templates
The following template IDs are available:
blank: Blank document with minimal formattingformal-letter: Standard formal letter formatformal-complaint: Letter for formal complaints or requestsjob-application: Letter for applying to jobsresignation: Letter for resigning from a positionacademic-paper: Format for academic research papersresume: Professional resume or curriculum vitaecode-documentation: Documentation for software projectsbook-chapter: Format for book chaptersfaq: Frequently asked questions formatpresentation: Script for presentations or speechesdata-report: Report with data analysislegal-document: Format for legal documents
Available Models
The following model IDs are available:
qwen: Qwen QwQ 32Bdeepseek: DeepSeek R1 Zeroolympiccoder32b: OlympicCoder 32Bolympiccoder7b: OlympicCoder 7Bgemma3-27b: Gemma 3 27Bgemma3-4b: Gemma 3 4Bgemma3-1b: Gemma 3 1Bdolphin-mistral: Dolphin Mistral 24Bmistral-small: Mistral Small 24Bllama-nemotron: Llama 3.1 Nemotron 70Bopenai: OpenAI GPT-4o
Example Request
// Using fetch API
const response = await fetch('https://api.promptpdf.com/v1/generate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
},
body: JSON.stringify({
prompt: 'Write a formal letter requesting a refund for a defective product purchased on March 10, 2025. The product was a laptop that stopped working after 2 days.',
template: 'formal-complaint',
modelType: 'qwen',
format: 'pdf'
})
});
const data = await response.json();Response
The response is a JSON object with the following structure:
Success Response
{
"success": true,
"content": "123 Maple Street\nAnytown, CA 91234\n\nMarch 19, 2025\n\nCustomer Service Department\nTech Solutions Inc.\n456 Oak Avenue\nAnytown, CA 91235\n\n**Subject: Formal Complaint Regarding Defective Laptop**\n\nDear Customer Service Manager:\n\nI am writing to file a formal complaint regarding a defective laptop I purchased from your store on March 10, 2025....",
"reasoning": null // Only present for certain models like deepseek
}Error Response
{
"success": false,
"error": {
"code": "invalid_parameters",
"message": "Invalid template specified"
}
}Webhook Notifications
For long-running operations, you can use webhooks to receive notifications when document generation is complete:
- Set
webhook: truein your request - Optionally specify a custom
webhookUrl - The API will return a job ID immediately
- When processing is complete, a POST request will be sent to your webhook URL
Webhook Request Format
{
"jobId": "job_123456789",
"status": "completed",
"content": "Generated document content...",
"timestamp": "2025-03-19T12:34:56Z"
}Error Codes
The API may return the following error codes:
| Code | Description |
|---|---|
| unauthorized | Invalid API key or insufficient permissions |
| invalid_parameters | One or more parameters are invalid |
| rate_limit_exceeded | You have exceeded your rate limit |
| model_unavailable | The requested AI model is currently unavailable |
| generation_failed | Document generation failed |
| server_error | Internal server error |
Next Steps
After generating a document, you may want to:
- Download the document as a PDF
- Convert the document to other formats
- Store the document in your system