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

# Create documents

> From a sentence or from your own text, in the format you need.

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

## From a sentence

Doconda writes it with AI. Any style you ask for in the sentence ("blue headings", "with a table of contents") is applied too.

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

## From your text

If you already have the content in Markdown, Doconda only lays it out. It is faster and cheaper.

```ts theme={null}
const doc = await doconda.documents.create({
  format: "docx",
  content: { markdown: "# Internal note\n\nMonday's meeting moves to 10:00." },
  style: "Lora font, blue headings, with page numbers",
})
```

## Which format you get

`format` decides the file. Word, PowerPoint and Excel also come with their PDF.

| You want | `format` |
| - | - |
| Word (+ PDF) | `docx` |
| Just the PDF | `pdf` |
| PowerPoint (+ PDF) | `pptx` |
| Excel (+ PDF) | `xlsx` |
| A web page with data | `artifact` (see [artifacts](/en/sdk/artifacts)) |

If you leave it out, Doconda infers it from `prompt` (and if that is not clear, it fails with `format_unclear` without
charging). Within a Word file or a PDF, Doconda decides on its own whether it is a report, a letter, a contract, a memo or
minutes, and gives it the matching base layout; you describe it in `prompt` and adjust the look with `style`. `doc.type`
tells you what it decided.

## With sources

`sources` holds your files: documents the AI reads before writing (up to 5) and images it places inside the
document (up to 10), together:

```ts theme={null}
import { readFile } from "node:fs/promises"

const law = await doconda.files.upload(await readFile("housing-law.pdf"), "housing-law.pdf")
const photo = await doconda.files.upload(await readFile("facade.jpg"), "facade.jpg")
const doc = await doconda.documents.create({
  format: "docx",
  prompt: "Summarize the main measures for a client",
  sources: [law.id, photo.id],
})
```

With your own Markdown (`content`), `sources` only carries images, and you place them with `![Caption](img:1)`.

## Download the result

```ts theme={null}
import { writeFile } from "node:fs/promises"

await writeFile("contract.docx", await doconda.documents.download(doc.id, "docx"))
await writeFile("contract.pdf", await doconda.documents.download(doc.id, "pdf"))
```

`doc.outputs` also includes the direct links (they expire after 5 minutes; `documents.outputs(id)` gives you new ones).

## Check how it turned out

```ts theme={null}
if (doc.status === "needs_review") {
  const report = await doconda.documents.report(doc.id)
  console.log(report.issues) // what could not be fixed automatically
}
console.log(doc.style_unsupported) // what you asked for and could not be applied, never silently ignored
```

| `status` | What it means |
| - | - |
| `ready` | Done, no problems. |
| `ready_with_warnings` | Done; the report has minor warnings. |
| `needs_review` | Done, but something is worth a look (it is in the report). |
| `failed` | It could not be done. No charge. `doc.error` says why. |

## In the background

To avoid waiting in the same call (for example, from a job queue):

```ts theme={null}
const doc = await doconda.documents.createInBackground({ format: "docx", prompt: "Quarterly report" })
// store doc.id and carry on…
const done = await doconda.documents.wait(doc.id)
```

`wait` follows the document's events and reconnects on its own if the connection drops.


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