AI document generation
Have ChatPRD's AI write, edit or rewrite a document from a prompt, then stream the result or poll for it.
POST /documents and PATCH /documents/{id} save Markdown you already wrote. The AI endpoints do the writing for you instead. ChatPRD's AI takes a prompt or instructions, follows your template and saved context, and saves the document the same way it does in a ChatPRD chat.
Every request creates (or continues) a real ChatPRD chat, so you can open the returned url and keep iterating in the app.
| Endpoint | Use it to |
|---|---|
POST /documents/ai-create | Write a new document from a prompt. |
POST /documents/{id}/ai-edit | Make targeted changes to an existing document from instructions. |
POST /documents/{id}/ai-rewrite | Rewrite an existing document from instructions. |
GET /documents/generations/{id} | Check a generation's status and get the finished document. |
The three AI endpoints need a key with connector:write and use your plan's AI usage. Generating a full document usually takes 30 seconds to a few minutes.
Request
curl https://app.chatprd.ai/api/connectors/v1/documents/ai-create \
-H "Authorization: Bearer $CHATPRD_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "PRD for SAML single sign-on for enterprise admins. Must support Okta and Azure AD.",
"templateId": "600",
"context": "Optional notes, research or transcripts to ground the document."
}'prompt(create) orinstructions(edit/rewrite) is required.contextis optional supporting material, up to 100,000 characters.templateId(create only) picks a template fromGET /templates. Without it, ChatPRD uses your default template, or the standard PRD template if you have no default.projectId(create only) uses that project's saved knowledge.organizationIdscopes the request to a team.stream: truereturns Server-Sent Events (see below).
There is nobody to answer follow-up questions during an API request, so the AI does not ask any. It makes reasonable assumptions and lists the important ones, plus any open questions, inside the document. Include the facts you care about in prompt or context.
Polling (default)
Without stream, the request returns 202 Accepted right away:
{
"id": "2ab4c357-…",
"kind": "create",
"status": "generating",
"threadId": "03e47aca-…",
"documentId": null,
"url": "https://app.chatprd.ai/chat/03e47aca-…",
"pollUrl": "/api/connectors/v1/documents/generations/2ab4c357-…"
}documentId is null for a new document until the AI saves it, so poll the generation id, not a document id. Poll GET /documents/generations/{id} every 5–10 seconds until status is no longer generating:
status | Meaning |
|---|---|
generating | Still running. |
ready | Saved. document holds id, title, contentMarkdown, url, threadId and updatedAt. |
failed | Nothing was saved, or the run timed out. error holds a code and message. |
Streaming
With "stream": true, the response is text/event-stream:
| Event | Data |
|---|---|
generation | Sent first. Same fields as the 202 response, including the id to poll. |
document.started | documentId and title once a new document exists. |
content.delta | delta: the next chunk of Markdown as the AI writes a new document or full rewrite. |
message.delta | delta: the AI's short summary of what it wrote or changed. |
document.completed | generationId, summary and the saved document. |
error | generationId, code and message. |
done | Last event. The stream then closes. |
Comment lines (: keep-alive) are sent every 15 seconds. Targeted edits don't stream content.delta, so wait for document.completed.
Treat document.completed as the final version. Formatting is normalized on save, so it can differ slightly from the joined content.delta chunks (for example, list bullets).
If the connection drops, the generation keeps running. Poll the id from the generation event to get the result.
Retries
Generation is not idempotent. After a dropped connection or a timeout, poll the generation you already started instead of sending the request again, or you may get a second document.
MCP
The ChatPRD MCP server has the same operations as tools: ai_create_document, ai_edit_document, ai_rewrite_document and get_document_generation. The AI tools wait up to about 50 seconds and return the finished document when it's ready. If it's still running, they return the generation id, and you poll it with get_document_generation.