> ## 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 a Word file or PDF from the Claude API

> Pass doconda.tools() as tools in messages.create: Claude calls create_document and you get the link to the .docx or the PDF.

Install `anthropic` and `doconda` (or `@anthropic-ai/sdk` and `@doconda/sdk`) and pass `doconda.tools()` as `tools` in
`messages.create`. When Claude calls `create_document`, you run it with `run()` and get the Word file (`.docx`) with its
PDF, or only the PDF if that's what you asked for, with their download links.

## Steps

1. Put your Anthropic key in `ANTHROPIC_API_KEY` and your Doconda key (dashboard → **API keys**) in `DOCONDA_API_KEY`.
2. Install the dependencies.
3. Run the tool-use loop: while `stop_reason` is `tool_use`, run each tool and hand back the `tool_result`.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
  # pip install anthropic doconda
  import json

  import anthropic
  from doconda import Doconda

  claude = anthropic.Anthropic()
  tools = Doconda().tools()
  specs = [{"name": t.name, "description": t.description, "input_schema": t.input_schema} for t in tools]
  messages = [{"role": "user", "content": "Write a PDF memo for the team: the office is closed on Friday"}]

  while True:
      res = claude.messages.create(model="claude-sonnet-5-5", max_tokens=4096, tools=specs, messages=messages)
      messages.append({"role": "assistant", "content": res.content})
      if res.stop_reason != "tool_use":
          break
      messages.append({"role": "user", "content": [
          {"type": "tool_result", "tool_use_id": b.id, "content": json.dumps(next(t for t in tools if t.name == b.name).run(b.input))}
          for b in res.content if b.type == "tool_use"
      ]})

  print("".join(b.text for b in res.content if b.type == "text"))
  ```

  ```ts TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
  // npm install @anthropic-ai/sdk @doconda/sdk
  import Anthropic from "@anthropic-ai/sdk"
  import { betaTool } from "@anthropic-ai/sdk/helpers/beta/json-schema"
  import { Doconda } from "@doconda/sdk"

  const anthropic = new Anthropic()
  const doconda = new Doconda()

  const message = await anthropic.beta.messages.toolRunner({
    model: "claude-opus-5-5",
    max_tokens: 4096,
    messages: [{ role: "user", content: "Prepare a short Word report on remote work" }],
    tools: doconda.tools().map((t) => betaTool({ ...t, run: async (input) => JSON.stringify(await t.run(input)) })),
  })

  console.log(message.content)
  ```
</CodeGroup>

In TypeScript, the Anthropic SDK's tool runner does the loop for you: the tools from `doconda.tools()` already have the
shape it expects. With the API's MCP connector (in beta), Claude calls Doconda's remote server without you running
anything; the code is in the [Claude guide](/en/agents/claude).

## What you get back

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

* With `format: "docx"`, `links` holds the editable Word file and its PDF; with `format: "pdf"`, only the PDF.
* `status`: `ready`, `ready_with_warnings`, `needs_review` or `failed` (not charged).
* Links expire after 5 minutes; Claude gets fresh ones with `get_document`.

## FAQ

<AccordionGroup>
  <Accordion title="Can Claude generate a .docx without tools?">
    No: the model's answer is text. With the tools, Claude decides the content and Doconda creates the file. If you
    already have the text, `documents.create(format="docx", content={"markdown": text})` converts it with no agent.
  </Accordion>

  <Accordion title="What about Claude Desktop or Claude Code?">
    Add the MCP server (`npx -y @doconda/mcp`) and ask in the chat. See [Claude](/en/agents/claude).
  </Accordion>

  <Accordion title="Does it work with Claude on Bedrock or Vertex AI?">
    Yes, the tools are standard JSON Schema. See [Amazon Bedrock](/en/agents/bedrock) and
    [Google Vertex AI](/en/agents/vertex).
  </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

* [Claude](/en/agents/claude): the full guide, with Claude Desktop, Claude Code and the MCP connector.
* [Quickstart](/en/quickstart).


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