> ## 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 from Amazon Bedrock with the Converse API

> Pass doconda.tools() as toolConfig to converse: the model calls create_document and you get links to the .docx and its PDF.

Install `doconda` (or `@doconda/sdk`) and pass `doconda.tools()` as the `toolConfig` of the Bedrock Converse API. When
the model asks for the `create_document` tool, you run it with `run()` and get back the Word file (`.docx`) and its PDF
with their download links.

## Steps

1. Enable a model in your Bedrock account and put its id in `BEDROCK_MODEL_ID`. AWS credentials come from your
   environment (`AWS_REGION`, `AWS_ACCESS_KEY_ID`…).
2. Create a Doconda API key in the dashboard, under **API keys**, and put it in `DOCONDA_API_KEY`.
3. Install the dependencies and run the Converse loop: while `stopReason` is `tool_use`, run the tool and hand the result
   back to the model.

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

  import boto3
  from doconda import Doconda

  bedrock = boto3.client("bedrock-runtime")
  tools = Doconda().tools()
  tool_config = {"tools": [{"toolSpec": {"name": t.name, "description": t.description, "inputSchema": {"json": t.input_schema}}} for t in tools]}
  messages = [{"role": "user", "content": [{"text": "Write a Word report on remote work at the company"}]}]

  while True:
      res = bedrock.converse(modelId=os.environ["BEDROCK_MODEL_ID"], messages=messages, toolConfig=tool_config)
      message = res["output"]["message"]
      messages.append(message)
      if res["stopReason"] != "tool_use":
          break
      results = []
      for block in message["content"]:
          if "toolUse" in block:
              use = block["toolUse"]
              out = next(t for t in tools if t.name == use["name"]).run(use["input"])
              results.append({"toolResult": {"toolUseId": use["toolUseId"], "content": [{"text": json.dumps(out)}]}})
      messages.append({"role": "user", "content": results})

  print("".join(block.get("text", "") for block in message["content"]))
  ```

  ```ts TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
  // npm install @aws-sdk/client-bedrock-runtime @doconda/sdk
  import { BedrockRuntimeClient, ConverseCommand, type Message } from "@aws-sdk/client-bedrock-runtime"
  import { Doconda } from "@doconda/sdk"

  const bedrock = new BedrockRuntimeClient({})
  const tools = new Doconda().tools()
  const toolConfig = { tools: tools.map((t) => ({ toolSpec: { name: t.name, description: t.description, inputSchema: { json: t.inputSchema } } })) }
  const messages: Message[] = [{ role: "user", content: [{ text: "Write a Word report on remote work at the company" }] }]

  while (true) {
    const res = await bedrock.send(new ConverseCommand({ modelId: process.env.BEDROCK_MODEL_ID, messages, toolConfig }))
    const message = res.output?.message
    if (!message) break
    messages.push(message)
    if (res.stopReason !== "tool_use") break
    const content = await Promise.all(
      message.content!.filter((b) => b.toolUse).map(async ({ toolUse }) => {
        const result = await tools.find((t) => t.name === toolUse!.name)!.run(toolUse!.input as Record<string, unknown>)
        return { toolResult: { toolUseId: toolUse!.toolUseId, content: [{ text: JSON.stringify(result) }] } }
      }),
    )
    messages.push({ role: "user", content })
  }
  ```
</CodeGroup>

The same loop works for your own agent built on Bedrock: the agent decides when to create the document and you only run
the tool.

## What you get back

The tool returns a short summary to the model, which passes it on to the user:

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

* `status`: `ready`, `ready_with_warnings`, `needs_review` (something in the report is worth checking) or `failed` (not
  charged).
* `links`: the editable Word file and its PDF. They expire after 5 minutes; the agent gets fresh ones with
  `get_document`.

## FAQ

<AccordionGroup>
  <Accordion title="Does it work with any Bedrock model?">
    With any model enabled in your account that supports tools in the Converse API. The tools are standard JSON Schema.
  </Accordion>

  <Accordion title="Can I ask for a PowerPoint or an Excel file with the same code?">
    Yes. `create_document` also creates PDF, PowerPoint and Excel files; the model picks `format` from what the user asks.
  </Accordion>

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

  <Accordion title="Where are the documents stored?">
    In the European Union (Ireland), and the AI that processes them also runs in the EU.
  </Accordion>
</AccordionGroup>

## Keep reading

* [Amazon Bedrock](/en/agents/bedrock): the full guide, also with the AI SDK.
* [Quickstart](/en/quickstart): your first document with the API.


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