> ## 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.

# Let users edit the documents your AI agent generates

> Create the Word file with the Doconda API, serve it from your server and open it in <DocondaEditor>: users touch it up and you save a new version.

To let users edit the documents your AI agent generates, create the file with the Doconda API and open it on your site
with the editor plugin (`@doconda/editor`). The agent writes the Word, PowerPoint or Excel file; the user touches it up
in their browser without leaving your product; and you save it as a new version of the document.

## Steps

1. Create an API key in the dashboard (**API keys**) and store it in `DOCONDA_API_KEY`. Install the SDK on your
   server: `npm install @doconda/sdk`.
2. Get the editor plugin (**Billing → Editor plugin**, with a 7-day free trial) and install it with the command from
   the dashboard (it needs React 19 or later):

```bash theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
npm install https://api.eu.doconda.com/v1/editor/package/edt_….tgz
```

3. On your server, create the document:

```ts theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
import { Doconda } from "@doconda/sdk"

const doconda = new Doconda()
const doc = await doconda.documents.create({
  format: "docx",
  prompt: "Residential lease agreement for €900 a month, with blue headings",
})
```

4. Serve it from a route of yours. The links in `doc.outputs` don't work as `src`: the browser can't read them from
   your site and they expire after 5 minutes. Download the file on the server:

```ts theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
// On your server (for example, the Next.js route app/api/documents/[id]/file/route.ts)
import { Doconda } from "@doconda/sdk"

const doconda = new Doconda()

export async function GET(req: Request, { params }: { params: Promise<{ id: string }> }) {
  const { id } = await params
  return new Response(await doconda.documents.download(id, "docx"))
}
```

5. In the browser, open it in the editor. The link has no extension, so pass `format`:

```tsx theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
<DocondaEditor src={`/api/documents/${id}/file`} format="docx" licenseKey="ek_eu_…" />
```

6. When the user is done, save it in Doconda as a new version (with its review, PDF and change report):

```ts theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
// In the browser: the file goes to your server
const body = new FormData()
body.append("file", await editor.current!.save())
await fetch(`/api/documents/${id}/versions`, { method: "POST", body })
```

```ts theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
// On your server (for example, the Next.js route app/api/documents/[id]/versions/route.ts)
export async function POST(req: Request, { params }: { params: Promise<{ id: string }> }) {
  const { id } = await params
  const res = await fetch(`https://api.eu.doconda.com/v1/documents/${id}/versions`, {
    method: "POST",
    headers: { Authorization: `Bearer ${process.env.DOCONDA_API_KEY}` },
    body: await req.formData(),
  })
  return Response.json(await res.json(), { status: res.status })
}
```

<Warning>
  The API key stays on your server, never in the browser. Check there too that the user may edit that document.
</Warning>

## Why this way

* The agent doesn't have to get it perfect the first time: the user fixes what's missing in a full Word editor.
* Whatever the editor does not touch is saved as is: styles, charts or notes are not lost.
* A hand-edited version uses no AI and isn't charged. See [Edit](/en/guides/edit#save-a-hand-edited-version).

## FAQ

<AccordionGroup>
  <Accordion title="Does it work with PowerPoint and Excel?">
    Yes. Create the document with `format: "pptx"` or `"xlsx"`, download it in that format and pass the same `format`
    to the editor.
  </Accordion>

  <Accordion title="Can I pass the file without a route?">
    Yes: if you already have the bytes in the browser (for example, from a response from your API), pass them with
    `file`.
  </Accordion>

  <Accordion title="What if I only want them to review it, not change it?">
    Add `readOnly`. See [DOCX viewer for React](/en/answers/docx-viewer-react).
  </Accordion>

  <Accordion title="Is it paid separately?">
    Yes: the editor plugin is purchased separately from the API, per organization, with unlimited documents and users. See
    [licence and domains](/en/editor/license).
  </Accordion>
</AccordionGroup>

## Keep reading

* [Quickstart](/en/quickstart) and [SDK: create documents](/en/sdk/create).
* [Editor plugin](/en/editor/introduction).


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