Edit Document
curl --request POST \
--url https://api.agentoffice.dev/v1/documents/{doc_id}/edits \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"editUid": "<string>",
"editInstructions": "<string>",
"lookupText": "<string>",
"useLargeModel": true
}
'import requests
url = "https://api.agentoffice.dev/v1/documents/{doc_id}/edits"
payload = {
"editUid": "<string>",
"editInstructions": "<string>",
"lookupText": "<string>",
"useLargeModel": True
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
editUid: '<string>',
editInstructions: '<string>',
lookupText: '<string>',
useLargeModel: true
})
};
fetch('https://api.agentoffice.dev/v1/documents/{doc_id}/edits', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.agentoffice.dev/v1/documents/{doc_id}/edits",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'editUid' => '<string>',
'editInstructions' => '<string>',
'lookupText' => '<string>',
'useLargeModel' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.agentoffice.dev/v1/documents/{doc_id}/edits"
payload := strings.NewReader("{\n \"editUid\": \"<string>\",\n \"editInstructions\": \"<string>\",\n \"lookupText\": \"<string>\",\n \"useLargeModel\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.agentoffice.dev/v1/documents/{doc_id}/edits")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"editUid\": \"<string>\",\n \"editInstructions\": \"<string>\",\n \"lookupText\": \"<string>\",\n \"useLargeModel\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.agentoffice.dev/v1/documents/{doc_id}/edits")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"editUid\": \"<string>\",\n \"editInstructions\": \"<string>\",\n \"lookupText\": \"<string>\",\n \"useLargeModel\": true\n}"
response = http.request(request)
puts response.read_body{
"detail": "Document not found or has expired"
}
{
"detail": "Edit operation timed out after 5 minutes"
}
{
"detail": "Edit operation failed: Unable to locate the specified text"
}
API Reference
Edit Document
Apply AI-powered edits to a document using natural language instructions
POST
/
v1
/
documents
/
{doc_id}
/
edits
Edit Document
curl --request POST \
--url https://api.agentoffice.dev/v1/documents/{doc_id}/edits \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"editUid": "<string>",
"editInstructions": "<string>",
"lookupText": "<string>",
"useLargeModel": true
}
'import requests
url = "https://api.agentoffice.dev/v1/documents/{doc_id}/edits"
payload = {
"editUid": "<string>",
"editInstructions": "<string>",
"lookupText": "<string>",
"useLargeModel": True
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
editUid: '<string>',
editInstructions: '<string>',
lookupText: '<string>',
useLargeModel: true
})
};
fetch('https://api.agentoffice.dev/v1/documents/{doc_id}/edits', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.agentoffice.dev/v1/documents/{doc_id}/edits",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'editUid' => '<string>',
'editInstructions' => '<string>',
'lookupText' => '<string>',
'useLargeModel' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.agentoffice.dev/v1/documents/{doc_id}/edits"
payload := strings.NewReader("{\n \"editUid\": \"<string>\",\n \"editInstructions\": \"<string>\",\n \"lookupText\": \"<string>\",\n \"useLargeModel\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.agentoffice.dev/v1/documents/{doc_id}/edits")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"editUid\": \"<string>\",\n \"editInstructions\": \"<string>\",\n \"lookupText\": \"<string>\",\n \"useLargeModel\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.agentoffice.dev/v1/documents/{doc_id}/edits")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"editUid\": \"<string>\",\n \"editInstructions\": \"<string>\",\n \"lookupText\": \"<string>\",\n \"useLargeModel\": true\n}"
response = http.request(request)
puts response.read_body{
"detail": "Document not found or has expired"
}
{
"detail": "Edit operation timed out after 5 minutes"
}
{
"detail": "Edit operation failed: Unable to locate the specified text"
}
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
string
required
The unique identifier of the document to edit (UUID from upload response)
Request Body
string
required
Client-provided UUID for idempotency and tracking. Generate a new UUID for
each edit request.
string
required
Natural language instructions describing the edit to apply (e.g., “Change the
title to ‘Q4 Report’ and update all dates to 2024”)
string
Optional text excerpt to help locate the section to edit in longer documents.
Use this to pinpoint the exact location for the edit.
boolean
Use a larger, more capable model for complex edits. Default is false.
Response
string
required
The UUID of the edit operation (same as request)
boolean
required
Whether the edit was successfully applied
number
required
Time taken to process the edit in seconds
string
required
Name of the edited document
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");
import requests
import uuid
doc_id = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890' # from upload response
url = f'https://api.agentoffice.dev/v1/documents/{doc_id}/edits'
headers = {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
payload = {
'editUid': str(uuid.uuid4()),
'editInstructions': 'Change the title to "Q4 Financial Report" and update the date to December 2024',
'lookupText': 'Financial Report',
'useLargeModel': False,
}
response = requests.post(url, headers=headers, json=payload)
result = response.json()
print(f"Edit applied: {result['editApplied']}")
print(f"Time taken: {result['timeToEdit']} seconds")
from agent_office import AgentOffice
from uuid import uuid4
import os
client = AgentOffice(api_key=os.getenv('AGENT_OFFICE_API_KEY'))
doc_id = "a1b2c3d4-e5f6-7890-abcd-ef1234567890" # from upload response
result = client.edit(
doc_id=doc_id,
edit_uid=str(uuid4()),
edit_instructions='Change the title to "Q4 Financial Report" and update the date to December 2024',
lookup_text="Financial Report",
use_large_model=False,
)
print(f"Edit applied: {result.edit_applied}")
print(f"Time taken: {result.time_to_edit} seconds")
curl -X POST 'https://api.agentoffice.dev/v1/documents/a1b2c3d4-e5f6-7890-abcd-ef1234567890/edits' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"editUid": "550e8400-e29b-41d4-a716-446655440000",
"editInstructions": "Change the title to \"Q4 Financial Report\" and update the date to December 2024",
"lookupText": "Financial Report",
"useLargeModel": false
}'
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
Text Replacement
Text Replacement
Replace all occurrences of “2023” with “2024”
Content Addition
Content Addition
Add a new section titled “Risk Analysis” after the Executive Summary with
placeholder text
Formatting Changes
Formatting Changes
Make all section headings bold and increase font size to 16pt
Complex Edits
Complex Edits
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, uselookupText 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"
}
{
"detail": "Edit operation timed out after 5 minutes"
}
{
"detail": "Edit operation failed: Unable to locate the specified text"
}
The document’s TTL (time to live) is automatically refreshed after each
successful edit.

