> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agentoffice.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Upload Document

> Upload a Word or PDF document to Agent Office

## Upload a Document

Upload a Microsoft Word (.docx) or PDF file to create a new document in Agent Office. The document will be stored and ready for AI-powered editing.

### Request Parameters

<ParamField body="file" type="file" required>
  The document file to upload (Word .docx or PDF)
</ParamField>

<ParamField body="ttl_seconds" type="integer">
  Time to live in seconds (300-21600). Default is 3600 (1 hour). The TTL is
  refreshed after each edit.
</ParamField>

<ParamField body="return_markdown" type="boolean">
  If true, returns a markdown representation of the document. Default is false.
</ParamField>

<ParamField body="tracked_changes" type="boolean">
  Enable tracked changes mode - stores a backup copy of the original document.
  When enabled, all edits will be shown as tracked changes when you download the
  document. Default is false.
</ParamField>

<ParamField body="author_name" type="string">
  Author name for tracked changes attribution. Only used if tracked\_changes is
  enabled. Default is "Anonymous".
</ParamField>

### Response

<ResponseField name="docId" type="string" required>
  Unique identifier for the uploaded document (UUID format)
</ResponseField>

<ResponseField name="name" type="string" required>
  Original filename of the uploaded document
</ResponseField>

<ResponseField name="createdAt" type="string" required>
  ISO 8601 timestamp when the document was created
</ResponseField>

<ResponseField name="fileType" type="string" required>
  MIME type of the uploaded file
</ResponseField>

<ResponseField name="imageAnnotations" type="array">
  Array of image annotations if the document contains images
</ResponseField>

<ResponseField name="markdown" type="string">
  Markdown representation of the document (only if return\_markdown=true)
</ResponseField>

### Example Response

```json theme={null}
{
  "docId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "name": "document.docx",
  "createdAt": "2024-01-15T10:30:00Z",
  "fileType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
  "imageAnnotations": null,
  "markdown": null
}
```

<Note>
  The `docId` from the response is required for all subsequent operations
  (editing, downloading, etc.)
</Note>

## Code Examples

<CodeGroup>
  ```javascript JavaScript (Fetch) theme={null}
  const formData = new FormData();
  formData.append("file", fileInput.files[0]);
  formData.append("ttl_seconds", "3600");
  formData.append("tracked_changes", "true");
  formData.append("author_name", "John Doe");

  const response = await fetch("https://api.agentoffice.dev/v1/documents/", {
    method: "POST",
    headers: {
      Authorization: "Bearer YOUR_API_KEY",
    },
    body: formData,
  });

  const result = await response.json();
  console.log("Document ID:", result.docId);
  ```

  ```python Python (Requests) theme={null}
  import requests

  url = 'https://api.agentoffice.dev/v1/documents/'
  headers = {
      'Authorization': 'Bearer YOUR_API_KEY'
  }

  with open('document.docx', 'rb') as f:
      files = {'file': f}
      data = {
          'ttl_seconds': 3600,
          'tracked_changes': True,
          'author_name': 'John Doe'
      }
      response = requests.post(url, headers=headers, files=files, data=data)

  result = response.json()
  print(f"Document ID: {result['docId']}")
  ```

  ```python Python SDK theme={null}
  from agent_office import AgentOffice
  import os

  client = AgentOffice(api_key=os.getenv('AGENT_OFFICE_API_KEY'))

  # Upload with tracked changes enabled
  doc = client.documents.create(
      file='document.docx',
      ttl_seconds=3600,
      tracked_changes=True,
      author_name='John Doe'
  )

  print(f"Document ID: {doc.doc_id}")
  ```

  ```bash cURL theme={null}
  curl -X POST 'https://api.agentoffice.dev/v1/documents/' \
    -H 'Authorization: Bearer YOUR_API_KEY' \
    -F 'file=@document.docx' \
    -F 'ttl_seconds=3600' \
    -F 'tracked_changes=true' \
    -F 'author_name=John Doe'
  ```
</CodeGroup>

## Tracked Changes Feature

When you enable `tracked_changes=true` at upload time, Agent Office stores a backup copy of your original document. When you make edits and download the document, all changes will be shown as Microsoft Word track changes, making it easy to review what was modified.

**Example workflow:**

1. Upload document with `tracked_changes=true`
2. Make edits using the edit endpoint
3. Download the document - changes will appear as Word track changes

<Tip>
  Use tracked changes when you need a clear audit trail of all modifications
  made to your document.
</Tip>

## Error Responses

<ResponseExample>
  ```json 400 Bad Request theme={null}
  {
    "detail": "File type not supported. Please upload a .docx or .pdf file"
  }
  ```

  ```json 413 File Too Large theme={null}
  {
    "detail": "File size exceeds maximum allowed size of 10MB"
  }
  ```
</ResponseExample>
