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

# Amazon Bedrock

> Genera Word, PowerPoint, Excel y PDF desde un agente con Amazon Bedrock.

```bash theme={null}
npm install ai @ai-sdk/amazon-bedrock @doconda/sdk
```

## Con el AI SDK

Las credenciales salen de tu entorno de AWS (`AWS_REGION`, `AWS_ACCESS_KEY_ID`…), como en el resto de tu código.

```ts theme={null}
import { bedrock } from "@ai-sdk/amazon-bedrock"
import { generateText, isStepCount, jsonSchema, tool } from "ai"
import { Doconda } from "@doconda/sdk"

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

const { text } = await generateText({
  model: bedrock(process.env.BEDROCK_MODEL_ID!), // cualquier modelo activado en tu cuenta de Bedrock
  tools,
  stopWhen: isStepCount(5),
  prompt: "Crea una presentación de 5 diapositivas sobre nuestros resultados del trimestre",
})
```

<Accordion title="Con la API Converse (@aws-sdk/client-bedrock-runtime)">
  ```bash theme={null}
  npm install @aws-sdk/client-bedrock-runtime @doconda/sdk
  ```

  ```ts theme={null}
  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: "Hazme un Excel con el presupuesto del evento" }] }]

  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 })
  }
  ```
</Accordion>


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