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

# How do I edit a Word document with AI without breaking its format?

> Ask for the change in a sentence with operation edit: Doconda changes only what you ask, new content copies the format and the rest stays identical.

To edit a Word document with AI without breaking its format, upload it and ask for the change in a sentence with
`operation: "edit"`. Doconda changes only what you ask and leaves the rest identical; new content copies the
document's formatting, so an added clause follows the numbering and look of the existing ones.

## Steps

1. Store your API key in `DOCONDA_API_KEY` and install the SDK (`pip install doconda` or `npm install @doconda/sdk`).
2. Upload the Word file with `files.upload` (or use the `doc_…` id of a document Doconda already made).
3. Ask for the changes, check the report and download the result.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
  from pathlib import Path
  from doconda import Doconda

  doconda = Doconda()  # reads the key from DOCONDA_API_KEY
  file = doconda.files.upload("contract.docx")
  edited = doconda.documents.create(
      operation="edit",
      file=file["id"],
      prompt="Headings in blue and add a confidentiality clause",
  )
  edits = doconda.documents.report(edited["id"])["edits"]
  # each change, with the text before and after
  Path("contract-edited.docx").write_bytes(doconda.documents.download(edited["id"], "docx"))
  ```

  ```ts TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
  import { readFile, writeFile } from "node:fs/promises"
  import { Doconda } from "@doconda/sdk"

  const doconda = new Doconda()
  const file = await doconda.files.upload(await readFile("contract.docx"), "contract.docx")
  const edited = await doconda.documents.create({
    operation: "edit",
    file: file.id,
    prompt: "Headings in blue and add a confidentiality clause",
  })
  const { edits } = await doconda.documents.report(edited.id)
  // each change, with the text before and after
  await writeFile("contract-edited.docx", await doconda.documents.download(edited.id, "docx"))
  ```
</CodeGroup>

## What you get back

* The same Word file, with only the requested changes, and its PDF.
* A report: in `edits`, each change with the text before and after. Whatever couldn't be done shows up as `rejected`,
  with the reason.
* The result is reviewed as in [Review](/en/guides/review) (tables that overflow, numbering gaps…).
* `status`: `ready`, `ready_with_warnings`, `needs_review` or `failed`. If the request can't be turned into changes,
  `failed` with `edit_not_understood`, not charged.

## Limits

* 50 pages maximum.
* Tracked changes and comments need `quality: "standard"` or `"best"`.
* `.doc` is accepted: the result comes out as `.docx`.

## FAQ

<AccordionGroup>
  <Accordion title="Why not ask the model to rewrite the document?">
    Rewriting it whole tends to lose styles, numbering and tables. With `edit` the rest of the document stays identical
    and new content follows its formatting.
  </Accordion>

  <Accordion title="Does it work with PowerPoint, Excel and PDF?">
    Yes, with the same call. In a PDF, if you ask for more than changing text, it comes out as Word (`pdf.converted`).
  </Accordion>

  <Accordion title="What if someone fixes the Word file by hand afterwards?">
    Save it as a new version with `POST /documents/{id}/versions`: it uses no AI and isn't charged. See
    [Edit](/en/guides/edit#save-a-hand-edited-version).
  </Accordion>
</AccordionGroup>

## Keep reading

* [Edit](/en/guides/edit) and [SDK: review and edit](/en/sdk/review-edit).
* [Quickstart](/en/quickstart).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.