> ## 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 to generate documents from a Mastra agent

> Wrap doconda.tools() with createTool and pass them to your Mastra Agent: it creates Word, PowerPoint, Excel or PDF files and returns links.

Install `@mastra/core` and `@doconda/sdk`, wrap each tool from `doconda.tools()` with `createTool` (it takes the JSON
Schema as is, no Zod needed) and pass them to your `Agent`. When you ask for a document, the agent calls
`create_document` and its answer carries the links to the Word, PowerPoint, Excel or PDF file.

## Steps

1. Put your Doconda API key (dashboard → **API keys**) in `DOCONDA_API_KEY` and your model provider's key (here,
   `ANTHROPIC_API_KEY`).
2. Install the dependencies: `npm install @mastra/core @doconda/sdk`.
3. Create the agent with the tools:

```ts theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
import { Agent } from "@mastra/core/agent"
import { createTool } from "@mastra/core/tools"
import { Doconda } from "@doconda/sdk"

const doconda = new Doconda()
const tools = Object.fromEntries(
  doconda.tools().map((t) => [
    t.name,
    createTool({ id: t.name, description: t.description, inputSchema: t.inputSchema, execute: (input) => t.run(input as Record<string, unknown>) }),
  ]),
)

const agent = new Agent({
  id: "documents",
  name: "Documents",
  instructions: "You create, review and edit documents with Doconda.",
  model: "anthropic/claude-sonnet-5-5", // or any other provider
  tools,
})

const { text } = await agent.generate("Create a 5-slide presentation on our quarterly results")
console.log(text)
```

`model` uses Mastra's `provider/model` format, which reads the provider's key from your environment.

With MCP instead of the SDK, use `MCPClient` from `@mastra/mcp` against `https://api.eu.doconda.com/mcp` and pass
`await mcp.listTools()` as `tools`. The tools come prefixed with the server name (`doconda_create_document`, …).

## What you get back

```json theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
{
  "id": "doc_01JAB3…",
  "format": "pptx",
  "status": "ready",
  "links": { "pptx": "https://…", "pdf": "https://…" },
  "links_note": "Links expire in 5 minutes: call get_document for fresh ones."
}
```

* `format`: `docx`, `pdf`, `pptx`, `xlsx` or `artifact`. Word, PowerPoint and Excel files come with their PDF.
* `status`: `ready`, `ready_with_warnings`, `needs_review` or `failed` (not charged).
* Links expire after 5 minutes; the agent gets fresh ones with `get_document`.

## FAQ

<AccordionGroup>
  <Accordion title="Can I use it inside a Mastra workflow?">
    Yes: the agent is the same. If a step doesn't need an agent, call
    `doconda.documents.create({ format: "docx", content: { markdown } })` directly with the previous step's text.
  </Accordion>

  <Accordion title="Where should I call Doconda from?">
    From your server, never the browser: your API key gives access to every document in the project.
  </Accordion>

  <Accordion title="How much does it cost?">
    You pay per delivered document; failed ones are not charged. See [pricing](/en/guides/account#pricing).
  </Accordion>
</AccordionGroup>

## Keep reading

* [Mastra](/en/agents/mastra): the full guide, also with the MCP client.
* [Quickstart](/en/quickstart).


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