Document Generation API
This page documents the REST API endpoints for creating, retrieving, regenerating, and updating documents produced by AI Employees.
All endpoints are prefixed with /api/document-generation/{ai_employee_id}/.
Create Document
Submit a document generation request.
| Property | Value |
|---|
| URL | /api/document-generation/{ai_employee_id}/documents |
| HTTP Method | POST |
| Protocol | REST (HTTP/JSON) |
| Header | Type | Required | Description |
|---|
Authorization | string | Yes | Bearer token |
Content-Type | string | Yes | application/json |
Request Body
| Field | Type | Required | Description |
|---|
persona_id | string | Yes | UUID of the AI Employee |
input | object | Yes | Input data for document generation |
options | object | No | Generation options (format, template, etc.) |
Example
curl -X POST https://your-instance.ema.co/api/document-generation/<ai_employee_id>/documents \
-H "Authorization: Bearer <access_token>" \
-H "Content-Type: application/json" \
-d '{
"persona_id": "<persona-uuid>",
"input": {
"topic": "Q4 2025 Sales Summary",
"data_source": "salesforce",
"date_range": "2025-10-01 to 2025-12-31"
}
}'
Response
| Field | Type | Description |
|---|
document_id | string | UUID of the created document |
status | string | Initial status (TRIGGERED) |
Retrieve Document
Retrieve the current status and content of a document. Use this endpoint to poll for completion.
| Property | Value |
|---|
| URL | /api/document-generation/{ai_employee_id}/documents/retrieve |
| HTTP Method | POST |
| Protocol | REST (HTTP/JSON) |
| Header | Type | Required | Description |
|---|
Authorization | string | Yes | Bearer token |
Content-Type | string | Yes | application/json |
Request Body
| Field | Type | Required | Description |
|---|
document_id | string | Yes | UUID of the document |
Example
curl -X POST https://your-instance.ema.co/api/document-generation/<ai_employee_id>/documents/retrieve \
-H "Authorization: Bearer <access_token>" \
-H "Content-Type: application/json" \
-d '{
"document_id": "<document-uuid>"
}'
Response
| Field | Type | Description |
|---|
document_id | string | UUID of the document |
status | string | Current status (TRIGGERED, PROCESSING, COMPLETED, FAILED) |
content | string | Generated document content (when COMPLETED) |
show_work | array | List of ShowWorkEntry objects with processing details |
error | string | Error message (when FAILED) |
Polling Pattern
# Poll every 5 seconds until status is COMPLETED or FAILED
while true; do
RESPONSE=$(curl -s -X POST https://your-instance.ema.co/api/document-generation/<ai_employee_id>/documents/retrieve \
-H "Authorization: Bearer <access_token>" \
-H "Content-Type: application/json" \
-d '{"document_id": "<document-uuid>"}')
STATUS=$(echo $RESPONSE | jq -r '.status')
if [ "$STATUS" = "COMPLETED" ] || [ "$STATUS" = "FAILED" ]; then
echo $RESPONSE | jq .
break
fi
echo "Status: $STATUS. Waiting..."
sleep 5
done
Regenerate Document (Preview)
Regenerate a document without replacing the original. This creates a preview that can be reviewed before finalizing.
| Property | Value |
|---|
| URL | /api/document-generation/{ai_employee_id}/documents/regenerate |
| HTTP Method | POST |
| Protocol | REST (HTTP/JSON) |
| Header | Type | Required | Description |
|---|
Authorization | string | Yes | Bearer token |
Content-Type | string | Yes | application/json |
Request Body
| Field | Type | Required | Description |
|---|
document_id | string | Yes | UUID of the original document |
input | object | No | Updated input data (overrides original) |
options | object | No | Updated generation options |
Example
curl -X POST https://your-instance.ema.co/api/document-generation/<ai_employee_id>/documents/regenerate \
-H "Authorization: Bearer <access_token>" \
-H "Content-Type: application/json" \
-d '{
"document_id": "<document-uuid>",
"input": {
"topic": "Q4 2025 Sales Summary - Revised",
"include_forecast": true
}
}'
Response
| Field | Type | Description |
|---|
preview_document_id | string | UUID of the preview document |
status | string | Status of the regeneration |
Update Document
Finalize changes to a document (e.g., after reviewing a preview).
| Property | Value |
|---|
| URL | /api/document-generation/{ai_employee_id}/documents/update |
| HTTP Method | POST |
| Protocol | REST (HTTP/JSON) |
| Header | Type | Required | Description |
|---|
Authorization | string | Yes | Bearer token |
Content-Type | string | Yes | application/json |
Request Body
| Field | Type | Required | Description |
|---|
document_id | string | Yes | UUID of the document to update |
content | string | No | Updated content |
metadata | object | No | Updated metadata |
Example
curl -X POST https://your-instance.ema.co/api/document-generation/<ai_employee_id>/documents/update \
-H "Authorization: Bearer <access_token>" \
-H "Content-Type: application/json" \
-d '{
"document_id": "<document-uuid>",
"content": "Updated document content here..."
}'
Document Status Values
| Status | Description |
|---|
TRIGGERED | Request accepted, queued for processing |
PROCESSING | AI Employee is generating the document |
COMPLETED | Document generated successfully |
FAILED | Generation failed (check error field for details) |