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.

PropertyValue
URL/api/document-generation/{ai_employee_id}/documents
HTTP MethodPOST
ProtocolREST (HTTP/JSON)

Headers

HeaderTypeRequiredDescription
AuthorizationstringYesBearer token
Content-TypestringYesapplication/json

Request Body

FieldTypeRequiredDescription
persona_idstringYesUUID of the AI Employee
inputobjectYesInput data for document generation
optionsobjectNoGeneration 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

FieldTypeDescription
document_idstringUUID of the created document
statusstringInitial status (TRIGGERED)

Retrieve Document

Retrieve the current status and content of a document. Use this endpoint to poll for completion.

PropertyValue
URL/api/document-generation/{ai_employee_id}/documents/retrieve
HTTP MethodPOST
ProtocolREST (HTTP/JSON)

Headers

HeaderTypeRequiredDescription
AuthorizationstringYesBearer token
Content-TypestringYesapplication/json

Request Body

FieldTypeRequiredDescription
document_idstringYesUUID 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

FieldTypeDescription
document_idstringUUID of the document
statusstringCurrent status (TRIGGERED, PROCESSING, COMPLETED, FAILED)
contentstringGenerated document content (when COMPLETED)
show_workarrayList of ShowWorkEntry objects with processing details
errorstringError 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.

PropertyValue
URL/api/document-generation/{ai_employee_id}/documents/regenerate
HTTP MethodPOST
ProtocolREST (HTTP/JSON)

Headers

HeaderTypeRequiredDescription
AuthorizationstringYesBearer token
Content-TypestringYesapplication/json

Request Body

FieldTypeRequiredDescription
document_idstringYesUUID of the original document
inputobjectNoUpdated input data (overrides original)
optionsobjectNoUpdated 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

FieldTypeDescription
preview_document_idstringUUID of the preview document
statusstringStatus of the regeneration

Update Document

Finalize changes to a document (e.g., after reviewing a preview).

PropertyValue
URL/api/document-generation/{ai_employee_id}/documents/update
HTTP MethodPOST
ProtocolREST (HTTP/JSON)

Headers

HeaderTypeRequiredDescription
AuthorizationstringYesBearer token
Content-TypestringYesapplication/json

Request Body

FieldTypeRequiredDescription
document_idstringYesUUID of the document to update
contentstringNoUpdated content
metadataobjectNoUpdated 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

StatusDescription
TRIGGEREDRequest accepted, queued for processing
PROCESSINGAI Employee is generating the document
COMPLETEDDocument generated successfully
FAILEDGeneration failed (check error field for details)

Last updated: Aug 12, 2026