Tutorials Dify

Dify Tutorial: Build Your First AI Chatbot

Seven steps — instance, model, prompt, knowledge base — to a chatbot that reads your company docs, plus the common sticking points and what drives each choice.

E
Eric Founder, Roamer Tech · · 8 min read

Want to start now? Deploy your Dify in 60 seconds

AI app platform — build your AI with no code. From NT$1,599/mo.

Subscribe to Dify

This guide takes you from a blank slate to a chatbot you can actually ship: one that talks in your tone of voice and answers by referring to the documents you upload.

No programming required, but you will need a language model API key — that cost is not included in your hosting fee, and it is the thing most people misunderstand at the start.

30-second overview

ItemDetails
What you buildA chatbot that answers questions from your documents
How long it takesAbout 30–60 minutes the first time
What you needA Dify instance, a model API key, a few documents
Do you need to codeNo
Extra costModel call charges, billed by usage
Where people get stuckModel settings that didn't save, document parsing failures

Before you start

A Dify instance

Self-hosting means dealing with a multi-container architecture (API, worker, frontend, PostgreSQL, Redis, a vector database), and the official recommendation starts at 2 cores and 4 GB. If you would rather not deal with that, RoamerHost has a fully managed version that is live about 60 seconds after payment. This article works through the full cost comparison between the two routes.

A model API key

Dify does not ship with a language model; you connect your own. OpenAI and Anthropic are the common choices — sign up on their platform and get a key.

The charges are separate: the hosting fee goes to your host, the model call charges go to the model provider. The amounts are tiny while you are testing, but once you are live they scale with usage.

A few documents to feed it

Product descriptions, terms of service, FAQs — anything works. For the first run, pick just three to five. With fewer documents it is easier to tell whether the results are good, and you can expand once the process works.

Step 1: Create a Dify instance and sign in

Once it is provisioned in the dashboard you get your own subdomain. The first time you open it you create an admin account; those credentials are your back-end entry point from then on, so store them somewhere safe.

Step 2: Configure the model provider

Paste in the API key

Go to Settings → Model Provider, pick the provider you want and paste in the API key.

Confirm it actually saved

This is the step people get stuck on most. After filling it in, go back to the list and check the provider shows as configured. If it doesn't, the key usually has whitespace around it, or it doesn't have permission for the model in question.

It is worth confirming on the provider's own platform that the key can make a successful call before you paste it here. Then when something breaks, you know which side it is on.

Step 3: Create a Chatbot app

In Studio, create a new app and choose the Chatbot type.

Ignore the other types for now: Chatbot is conversational, Workflow is process-driven, and an Agent decides for itself which tool to use. Chatbot is the simplest starting point; when you want to go further, see workflow orchestration.

Step 4: Write the prompt

Start with role and boundaries

The prompt sets the bot's personality and its rules. In practice, three things do most of the work:

  • Say clearly who it is — "You are the customer support assistant for Company X"
  • Say clearly what to do when it doesn't know — the most important line; leave it out and it will make things up
  • Say clearly what tone to use — formal or casual, emoji or no emoji

Don't write too much at once

Start with five or six lines that work, test them, then add more. If you write a two-hundred-line prompt on day one, you won't know which line caused the problem.

Step 5: Create a knowledge base and upload documents

This step decides whether the bot talks nonsense. After upload, the system parses the documents, splits them into chunks and builds an index, then pulls the most relevant chunks for each question.

Chunk size, indexing method and retrieval settings all affect the results; the details are in the knowledge base guide. Stick with the defaults the first time and only tune once you see a real problem.

Step 6: Connect the knowledge base to the app

Back in your chatbot, add the knowledge base you just built under Context. Skip this step and the bot will never read those documents — another very common omission.

Step 7: Test and publish

Test with real questions, not the ones you imagine

Take ten questions customers have actually asked and work through them one at a time. The questions you invent tend to be exactly the ones your documents answer most clearly, so they won't expose the real gaps.

Look at which chunk it cited

Each answer shows its cited sources. When an answer is wrong, look first at what it retrieved: if the retrieved chunk is irrelevant, the problem is in the knowledge base; if it retrieved the right chunk and still answered wrong, the problem is in the prompt.

That one distinction saves an enormous amount of guesswork.

Next steps

Three things to do after launch

1. Write down the questions it got wrong

In the bot's first week live, the most valuable output is not what it got right — it is the list of what it got wrong. Every wrong answer maps to a specific gap: something the documents don't cover, a badly split chunk, or a prompt that didn't spell things out.

The practical approach is to keep a table: the question, what it answered, what the correct answer is, and which layer the problem was in. After twenty entries you will find the errors cluster around just a few causes.

2. Re-sync your documents regularly

When a source document changes, the knowledge base does not update itself. Content that changes — prices, policies, what's in scope — is especially dangerous, because the bot will confidently serve the old version.

A more realistic approach is to bind "update the knowledge base" into an existing process: re-upload right after you change a price, rather than setting a separate reminder.

3. Keep an eye on model costs

The hosting fee is fixed; the model charges are not. As usage grows, that bill grows with it. The two variables that matter most are how much content you send to the model each time (driven by Top-K) and the number of conversation turns.

For the first two weeks after launch it is worth checking usage once a day to establish what normal looks like. Only then can you recognize abnormal.

FAQ

Q: Do I have to pay to use it?

Dify itself is open source. You pay for two things: the environment it runs in (your own server, or a managed monthly fee) and the language model calls. Most model providers give you a small free allowance for testing.

Q: What if the bot makes up answers?

Start by stating explicitly in the prompt: "If you can't find the information, say you don't know — don't guess." If it still invents answers, the knowledge base is usually failing to retrieve the right chunk — the cited sources tell you which case you're in.

Q: I uploaded a PDF and nothing happened

Large or scanned PDFs are resource-hungry to parse; it may just take a while, or it may fail. For scans, convert them to text before uploading. If you keep hitting this, see resource limits to work out whether your specs are too small.

Q: Can I switch models?

Yes, at any time in the app settings. After switching you usually have to retune the prompt — the same prompt performs more differently across models than most people expect.

Q: How do I put the finished bot on my website?

Dify provides an embeddable web widget and an API. For deep integration with your own systems, go with the API; if you just want a chat window on the page, embedding is the fastest route.

Sources and further reading

The interface and features change between versions, so check against the official documentation before you start:

Further reading

Want someone to build it for you?

If you would rather not assemble these processes yourself, or the scale is big enough that you want someone planning alongside you, Roamer Tech (RoamerHost's parent company) takes on business process automation and custom AI agent development:

Ready to get started with Dify?

60 seconds after you subscribe, Dify is installed for you — an isolated container with hard resource limits you never share, and HTTPS out of the box.

Subscribe to Dify

Billed monthly · no contract · cancel anytime

Hi, I'm Roamer! Tap me anytime with a question and I'll help you out.

Roamer

Roamer - AI assistant

Online
Roamer

Ask me anything, anytime — I'll do my best to help!

Powered by RoamerHost AI