All Articles
chatbotsJune 28, 2026

How to Build a Customer Support Bot with GPT-4o

A step-by-step guide to building a production-ready customer support chatbot using GPT-4o's function calling and knowledge retrieval.

chatgpt gpt4o chatbot customer-support

How to Build a Customer Support Bot with GPT-4o

Customer support is one of the best use cases for AI. In this guide, we'll build a bot that can answer questions, escalate to humans, and learn from feedback.

What You'll Build

A chatbot that:

  • Answers FAQs from a knowledge base
  • Detects when to escalate to a human
  • Logs conversations for review

Prerequisites

  • OpenAI API key
  • Basic Python knowledge
  • 60 minutes

Step 1: Set Up the Project

pip install openai python-dotenv

Create a .env file:

OPENAI_API_KEY=sk-...

Step 2: Define Your Knowledge Base

Store your FAQs in a JSON file:

{
  "faq": [
    { "q": "What are your hours?", "a": "We're open 9am-6pm IST, Monday to Friday." },
    { "q": "How do I reset my password?", "a": "Click 'Forgot password' on the login page." }
  ]
}

Step 3: Build the Chat Function

from openai import OpenAI
import json

client = OpenAI()

def chat_with_bot(user_message: str, history: list) -> str:
    system_prompt = """You are a helpful customer support agent for Coderefer.
    Answer questions based on the FAQ. If you can't help, say: 'Let me connect you with a human agent.'
    """

    messages = [{"role": "system", "content": system_prompt}] + history + [
        {"role": "user", "content": user_message}
    ]

    response = client.chat.completions.create(
        model="gpt-4o",
        messages=messages
    )

    return response.choices[0].message.content

Wrapping Up

You now have a basic support bot. Next steps: add a vector database for larger knowledge bases, and integrate with WhatsApp or Slack.