Skip to content
WebDev Path

AI chatbot or document assistant

A streaming chatbot that answers from a business's facts or a set of documents, with cost and safety limits.

  • Next.js
  • Vercel AI SDK
  • OpenAI or Anthropic

The project for module 6, AI features, deployment and jobs. It proves: ai integration, streaming, cost control and production deployment.

Who it's for

  • As a visitor, I get answers as they stream in
  • As a visitor, I can stop a long answer
  • As the owner, I know nobody can run up my AI bill

Pick your version

Choose one theme, or your own idea. Same skills, but your portfolio won't look like everyone else's.

  1. Option A

    Chat with a PDF that cites the page of each answer

  2. Option B

    Support bot for a made-up shop that answers from its FAQ

  3. Option C

    Study helper that quizzes you on your own notes

Warm up first

Two short builds that practise the skills this project needs. About 3.5 hours in total.

Safe streaming AI endpoint

2 h

One API route that streams an AI answer, with input and cost limits.

  1. Read the API key only on the server
  2. Limit the question to 500 characters with Zod
  3. Set max_tokens and stream the reply
  4. Return a friendly error if the AI service fails

Done when: The key never reaches the browser, and long or empty questions are rejected.

  • AI APIs
  • Streaming
  • Cost control

README and 2-minute demo

1.5 h

Turn your best project into something a recruiter or client understands in 2 minutes.

  1. Write a README with a screenshot, live link, features, stack and setup steps
  2. Add a short Security or Decisions section
  3. Record a 2-minute screen video: problem, demo, one technical choice
  4. Pin the repo on your GitHub profile

Done when: A non-developer friend can explain what your project does after watching.

  • Writing
  • Presenting
  • Personal brand

Build plan

7 steps in order. Each one ends with a clear check, so you always know when to move on.

  1. Keep the key safe

    Create a Next.js route handler that calls the AI API. Store the key in .env.local only.

    Done when: Searching your browser's page source and network tab never shows the key.

    Stuck? Show a hint

    Only read process.env.OPENAI_API_KEY in server files. Add the server-only package to make leaks a build error.

  2. Stream the answer

    Stream the model's reply to the page word by word.

    Done when: Text appears as it's written, not all at once after a wait.

    Stuck? Show a hint

    Return a ReadableStream from the route and read it with response.body.getReader() in the browser.

  3. Add stop and retry

    Let users stop a long answer and retry a failed one.

    Done when: Stop ends the stream right away and Retry sends the last question again.

    Stuck? Show a hint

    Pass an AbortController's signal to fetch, and call abort() on Stop.

  4. Answer from your facts only

    Put your facts or document chunks in the system prompt and tell the model to say "I don't know" otherwise.

    Done when: Asking something outside your facts gets "I don't know", not a made-up answer.

    Stuck? Show a hint

    Set temperature to 0 and keep a list of 5 test questions, including 2 that shouldn't be answered.

  5. Protect your bill

    Validate input length, cap max_tokens, and rate limit each visitor.

    Done when: Sending 50 requests fast gets blocked after your limit.

    Stuck? Show a hint

    Also set a monthly budget in your AI provider's dashboard. Code limits can fail, a budget can't.

  6. Go further with retrieval

    Optional: split a PDF into chunks, embed them, and send only the closest chunks to the model.

    Done when: Answers come with the page number they came from.

    Stuck? Show a hint

    Compare your build with the reference project below once yours works.

  7. Ship it

    Deploy on Vercel with the key as an environment variable, and write a README with a Security section.

    Done when: The live chatbot works on your phone.

    Stuck? Show a hint

    Show the rate limit and the "I don't know" answer in your demo video. It proves you thought about real users.

Requirements

Tick each one when it's done. Saved to your account.

Go further

Optional. One of these makes your project stand out from the tutorial version.

  • Answer from uploaded PDFs (retrieval)
  • Save chat history for signed-in users

Starter kit

Free APIs, tools and docs for this project.

Compare with a finished version

DocChat: AI PDF chatbot (Next.js + OpenAI, RAG)

Build your own version first. Then open this to compare how a finished app handles the same problems, and borrow ideas.

Submit

Tick the 5 remaining requirements to submit.