APIAI documents

AI rewrite a document

POST /documents/{id}/ai-rewrite

POST
/documents/{id}/ai-rewrite

Authorization

apiKey connector:write
headerAuthorizationBearer <token>

ChatPRD API key from Settings → API Keys, sent as Authorization: Bearer <key>. Read-only keys carry the connector:read scope; read/write keys also carry connector:write. Requires a Pro, Team or Enterprise plan.

Scope: connector:write

Path Parameters

id*string

Document ID (UUID), as returned by GET /documents.

Formatuuid

Request Body

application/json
  1. body
instructions*string

What to change.

Length1 <= length <= 20000
context?string

Notes or requirements the AI should use.

Lengthlength <= 100000
organizationId?string

Organization the document belongs to, if any.

stream?boolean

Return Server-Sent Events instead of 202.

Defaultfalse

Response Body

Server-Sent Events stream (when stream: true). Each event's data is JSON.

text/event-stream
  1. response

SSE events, in order: generation (id, kind, threadId, documentId, url) first; document.started (documentId, title) once a new document exists; content.delta (documentId, delta) with Markdown chunks while create/rewrite write the document; message.delta (delta) for the AI's short summary; then document.completed (generationId, summary, document) or error (generationId, code, message); finally done. Comment lines (: keep-alive) are sent every 15s.

event*string
Value in"generation""document.started""content.delta""message.delta""document.completed""error""done"
data*
Example Request
curl -X POST 'https://app.chatprd.ai/api/connectors/v1/documents/497f6eca-6276-4993-bfeb-53cbbbba6f08/ai-rewrite' \  -H 'Content-Type: application/json' \  -d '{  "instructions": "Rewrite this for an executive audience in under one page."}'
Example Response
{  "event": "generation",  "data": {}}