Skip to main content
POST
/
v1
/
documents
/
{doc_id}
/
edits
Edit Document
curl --request POST \
  --url https://api.agentoffice.dev/v1/documents/{doc_id}/edits \
  --header 'Content-Type: application/json' \
  --data '{
  "editUid": "<string>",
  "editInstructions": "<string>",
  "lookupText": "<string>",
  "trackedChanges": true,
  "useLargeModel": true
}'
{
  "detail": "Document not found or has expired"
}

Edit a Document

Apply AI-powered edits to your document using natural language instructions. The API uses advanced language models to understand your intent and make precise edits to the document.

Path Parameters

doc_id
string
required
The unique identifier of the document to edit (UUID from upload response)

Request Body

editUid
string
required
Client-provided UUID for idempotency and tracking. Generate a new UUID for each edit request.
editInstructions
string
required
Natural language instructions describing the edit to apply (e.g., “Change the title to ‘Q4 Report’ and update all dates to 2024”)
lookupText
string
Optional text excerpt to help locate the section to edit in longer documents. Use this to pinpoint the exact location for the edit.
trackedChanges
boolean
Apply changes as tracked changes (like Word’s track changes). Currently disabled.
useLargeModel
boolean
Use a larger, more capable model for complex edits. Default is false.

Response

editUid
string
required
The UUID of the edit operation (same as request)
editApplied
boolean
required
Whether the edit was successfully applied
timeToEdit
number
required
Time taken to process the edit in seconds
documentName
string
required
Name of the edited document
documentId
string
required
UUID of the edited document

Code Examples

import { v4 as uuidv4 } from "uuid";

const docId = "a1b2c3d4-e5f6-7890-abcd-ef1234567890"; // from upload response

const response = await fetch(
  `https://api.agentoffice.dev/v1/documents/${docId}/edits`,
  {
    method: "POST",
    headers: {
      Authorization: "Bearer YOUR_API_KEY",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      editUid: uuidv4(),
      editInstructions:
        'Change the title to "Q4 Financial Report" and update the date to December 2024',
      lookupText: "Financial Report",
      useLargeModel: false,
    }),
  }
);

const result = await response.json();
console.log("Edit applied:", result.editApplied);
console.log("Time taken:", result.timeToEdit, "seconds");

Example Response

{
  "editUid": "550e8400-e29b-41d4-a716-446655440000",
  "editApplied": true,
  "timeToEdit": 3.45,
  "documentName": "report.docx",
  "documentId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}

Edit Instructions Best Practices

Be specific and clear: The more specific your instructions, the better the results.
  • ✅ Good: “Change the company name from ‘Acme Corp’ to ‘Global Industries Inc.’ in the header”
  • ❌ Vague: “Update the company info”

Examples of Edit Instructions

Replace all occurrences of "2023" with "2024"
Add a new section titled "Risk Analysis" after the Executive Summary with placeholder text
Make all section headings bold and increase font size to 16pt
In the financial table, update Q4 revenue to $2.5M and recalculate the total. 
Also add a footnote explaining the increase.

Using lookupText for Long Documents

For documents longer than a few pages, use lookupText to help the AI locate the correct section:
{
  editUid: uuidv4(),
  editInstructions: 'Change the budget amount to $150,000',
  lookupText: 'Marketing Budget Q4' // This helps locate the right section
}

Sequential Edits

All edits to the same document are queued and processed sequentially. Each edit waits for the previous one to complete:
// Edit 1
await fetch(`https://api.agentoffice.dev/v1/documents/${docId}/edits`, {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    editUid: uuidv4(),
    editInstructions: "Update the title",
  }),
});

// Edit 2 - will wait for Edit 1 to complete
await fetch(`https://api.agentoffice.dev/v1/documents/${docId}/edits`, {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    editUid: uuidv4(),
    editInstructions: "Add a conclusion section",
  }),
});

Error Responses

{
  "detail": "Document not found or has expired"
}
The document’s TTL (time to live) is automatically refreshed after each successful edit.
I