> ## 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 generate a Word document from a prompt in Node.js?

> Install @doconda/sdk and call documents.create with format docx and a prompt: you get an editable .docx and its PDF, no templates.

To generate a Word document from a prompt in Node.js, install `@doconda/sdk` and call `documents.create` with
`format: "docx"` and what you want in `prompt`. Doconda writes the content, applies any style you ask for in the same
sentence and returns an editable `.docx` and its PDF, with no templates or layout code.

## Steps

1. Create an API key in the dashboard, under **API keys**, and store it in `DOCONDA_API_KEY`.
2. Install the SDK (Node 20 or later, no runtime dependencies): `npm install @doconda/sdk`.
3. Create the document and save it to disk.

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

const doconda = new Doconda()
const doc = await doconda.documents.create({
  format: "docx",
  prompt: "Report on the housing law with blue centered headings",
})

console.log(doc.status) // "ready"
await writeFile("report.docx", await doconda.documents.download(doc.id, "docx"))
await writeFile("report.pdf", await doconda.documents.download(doc.id, "pdf"))
```

`documents.create` waits for the document to be ready, like a call to an LLM. If it takes longer than 120 seconds,
the SDK keeps waiting for you.

## What you get back

* An editable `.docx`: the look lives in the Word styles, and the layout adapts to the kind of document (`doc.type`:
  report, letter, contract, memo or minutes).
* Its PDF, and `doc.outputs` with direct links (they expire after 5 minutes; `documents.outputs(id)` gives you new
  ones).
* `doc.status`: `ready`, `ready_with_warnings`, `needs_review` or `failed` (not charged; `doc.error` says why).
* `doc.style_unsupported`: whatever you asked for that couldn't be applied.

## Limits

* Use the SDK on your server, never in the browser: your API key gives access to every document in the project.
* With `quality: "fast"` you get the basic style; charts, tracked changes or your template's design need `standard`
  or `best`.
* If you leave out `format` and the sentence doesn't make the file type clear, it fails with `format_unclear` and
  isn't charged.

## FAQ

<AccordionGroup>
  <Accordion title="Does it work in serverless functions?">
    Yes. The SDK works on Node 20 or later, serverless functions included.
  </Accordion>

  <Accordion title="What if my model already wrote the text?">
    Pass it in `content: { markdown }`: Doconda only lays it out, faster and cheaper.
  </Accordion>

  <Accordion title="Can I show the document while it's being written?">
    Yes, with `documents.stream`. See [Watch the document live](/en/sdk/stream).
  </Accordion>

  <Accordion title="Is there a Python SDK?">
    Yes, with the same methods: `pip install doconda`. See [Python SDK](/en/sdk/python).
  </Accordion>
</AccordionGroup>

## Keep reading

* [TypeScript SDK](/en/sdk/introduction) and [Create documents](/en/sdk/create).
* [Quickstart](/en/quickstart).


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