Skip to main content
You’ll build a chat in Next.js: the user asks for a document (“a welcome letter for a new client”) and the bot replies with the link to download the Word file. The agent calls Doconda from your server, so the API key never reaches the browser.

What you need

  • A Next.js project with the App Router (Node 20+).
  • A Doconda API key in DOCONDA_API_KEY. Create it in the dashboard, under API keys.
  • Your model provider’s key. Here we use Anthropic (ANTHROPIC_API_KEY); any other AI SDK provider works.

1. Install the dependencies

2. Create the chat route

doconda.tools() gives you Doconda’s tools (create, upload, review, edit…). You turn them into AI SDK tools and pass them to streamText.
app/api/chat/route.ts

3. Create the chat page

useChat sends the messages to /api/chat and renders the reply as it arrives.
app/page.tsx

4. Try it

Open http://localhost:3000 and type “Make me a welcome letter for a new client”.

Result

The agent calls create_document, waits until the Word file is ready and gets this back:
The bot’s reply contains the link to the Word file (.docx) and to its PDF. The links expire after 5 minutes; if the user comes back later, the agent calls get_document and gets new ones.

Next steps