Coderefercoderefer
CoursesWebinarsBlogAbout
Coderefercoderefer

Discover. Learn. Automate. Grow.

Learn

  • Courses
  • Webinars
  • Blog
  • Search

Company

  • About
  • Contact
  • FAQ

Legal

  • Privacy Policy
  • Terms of Service
  • Refund Policy
© 2026 Coderefer. All rights reserved.
HomeBlogHow to Build a Customer Support Bot with GPT-4o
chatbotsJune 28, 20262 min read

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.

V

Vamsi Tallapudi

Manager, Architect Technology at Cognizant

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

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

Watch: Building AI Support Bots

How to Build an AI Customer Support Chat Bot - Full Tutorial

You now have a basic support bot. Next steps: add a vector database for larger knowledge bases, and integrate with WhatsApp or Slack. OpenAI's new ChatGPT Work mode can now handle multi-step customer interactions automatically, so also consider whether an agentic approach fits your use case. See our full list of AI tools replacing manual work in 2026 for more options.

chatgpt gpt4o chatbot customer-support

Comments

    Get AI tricks that save you hours every week

    New AI tools, automation workflows, and course drops — straight to your inbox. Join 2,400+ builders.

    Read Next

    ChatGPT and Codex Will Share One Usage Limit From December
    ai-tools

    ChatGPT and Codex Will Share One Usage Limit From December

    OpenAI is merging ChatGPT chat and Codex into one shared token-based usage allowance for Plus, Pro, and Business starting December 2026. Here's what changes.

    November 2, 20266 min read
    GPT-6 Pro's Parallel Agents: What ChatGPT's Multi-Agent Mode Does
    ai-tools

    GPT-6 Pro's Parallel Agents: What ChatGPT's Multi-Agent Mode Does

    GPT-6 Pro in ChatGPT now splits tasks across multiple agents running at once. Here's who gets it, what it actually does, and how it compares to Claude Code subagents.

    October 18, 20266 min read
    ChatGPT Work: OpenAI's New AI Agent That Actually Does Your Work
    ai-tools

    ChatGPT Work: OpenAI's New AI Agent That Actually Does Your Work

    OpenAI launched ChatGPT Work — an agentic mode powered by GPT-5.6 that connects to Slack, Gmail, Google Drive, and Salesforce to produce finished spreadsheets, reports, and slide decks. Here's how it works, what it costs, and whether it's worth it.

    July 23, 20264 min read
    View all posts →