Tutorial

AI Customer Service API: Build a Support Chatbot in 2026

April 16, 2026 · 9 min read

AI customer service works best when it is narrow, grounded, and honest about escalation. Start by answering repetitive questions from your docs and policies, then route billing, refund, account, and high-risk issues to a human or sales workflow.

AIPower gives support teams one OpenAI-compatible API for GPT, Claude, Gemini, DeepSeek, Qwen, and other China + global models, with unified billing, logs, routing, WeChat Pay, Alipay, card payments, Team, and BYOK options.

For the dedicated support use case, see AI Customer Service API.

Architecture

User Message → Your Backend → AI API → Response
                   ↓
         Knowledge Base (FAQs, docs, product info)
                   ↓
         Escalation Logic (complex issues → human agent)

The API should be the model layer, not the whole support system. Your app should still own user identity, conversation history, knowledge snippets, ticket creation, and escalation rules.

Step 1: Knowledge-Grounded Chatbot

The key to a good support bot is grounding it with your product knowledge:

from openai import OpenAI

client = OpenAI(base_url="https://api.aipower.me/v1", api_key="YOUR_KEY")

KNOWLEDGE_BASE = """
Product: AcmeSaaS — Project Management Tool
Pricing: Free (5 projects), Pro $12/mo (unlimited), Enterprise $49/mo
Features: Kanban boards, Gantt charts, time tracking, invoicing
Common issues:
- Can't login: Clear cookies, try password reset at /reset-password
- Billing issue: Contact billing@acme.com
- Feature request: Submit at feedback.acme.com
- Data export: Settings > Export > Choose format (CSV/JSON/PDF)
Refund policy: Full refund within 14 days, pro-rated after
"""

def support_chat(user_message, conversation_history):
    messages = [
        {
            "role": "system",
            "content": f"""You are a friendly customer support agent for AcmeSaaS.
Use ONLY the following knowledge base to answer questions.
If you don't know the answer, say "Let me connect you with our team" and set escalate=true.
Be concise and helpful. Never make up features or policies.

{KNOWLEDGE_BASE}"""
        },
        *conversation_history,
        {"role": "user", "content": user_message}
    ]

    response = client.chat.completions.create(
        model="deepseek/deepseek-chat",  # Efficient default for support
        messages=messages,
        max_tokens=300,
        temperature=0.3,  # Low temperature for consistent, factual responses
    )
    return response.choices[0].message.content

Step 2: Intent Classification for Smart Routing

def classify_intent(message):
    """Classify user intent to route appropriately."""
    response = client.chat.completions.create(
        model="zhipu/glm-4-flash",  # Low-cost model for classification
        messages=[{
            "role": "user",
            "content": f"Classify this customer message into ONE category: "
                       f"billing, technical, feature_request, account, general.\n"
                       f"Message: {message}\nCategory:"
        }],
        max_tokens=10,
        temperature=0,
    )
    return response.choices[0].message.content.strip().lower()

Step 3: Escalation Logic

ESCALATION_TRIGGERS = [
    "speak to a human", "talk to someone", "manager",
    "refund", "cancel subscription", "legal", "lawsuit",
    "not working at all", "lost all my data",
]

def should_escalate(message, ai_response):
    msg_lower = message.lower()
    # Check explicit escalation requests
    if any(trigger in msg_lower for trigger in ESCALATION_TRIGGERS):
        return True
    # Check if AI couldn't answer
    if "connect you with" in ai_response or "don't have" in ai_response:
        return True
    return False

Step 4: Multi-Language Support

def support_chat_multilingual(message, conversation_history, language="auto"):
    """Auto-detect language and respond in the same language."""
    system = f"""You are a customer support agent for AcmeSaaS.
Respond in the SAME language as the user's message.
Knowledge base: {KNOWLEDGE_BASE}"""

    # Qwen is a strong default for Chinese and multilingual support
    model = "qwen/qwen-plus" if language in ("zh", "ja", "ko", "auto") else "deepseek/deepseek-chat"

    response = client.chat.completions.create(
        model=model,
        messages=[{"role": "system", "content": system}, *conversation_history,
                  {"role": "user", "content": message}],
    )
    return response.choices[0].message.content

Support Routing Pattern

Support jobModel routeWhy
FAQ / status / policyGLM, Qwen, or DeepSeekFast, predictable, and efficient for repetitive questions.
Chinese supportQwen or DeepSeekStrong Chinese answers and local-context coverage.
Complex troubleshootingClaude, GPT, or GeminiBetter for longer context, careful reasoning, and multi-step debugging.
Billing / invoice / BYOKHuman or sales intakeHigh purchase intent. Capture the lead instead of hiding it inside a chat log.

This pattern is the profit lever: use efficient models for repetitive support, reserve premium models for cases where quality matters, and move commercial questions into a sales workflow.

Production Tips

  • Always ground with knowledge: Never let the AI make up answers. Provide explicit knowledge and instruct it to escalate when unsure.
  • Use low temperature: 0.2-0.3 for support to keep responses consistent and factual.
  • Log everything: Store conversations for quality review and knowledge base improvement.
  • Set max tokens: Keep responses concise (200-300 tokens). Users want quick answers.
  • Add feedback buttons: Let users rate AI responses to continuously improve.

Build your AI support bot with AIPower's AI Customer Service API: one account, China + global models, unified billing, stable routing, and Team/BYOK paths when your support volume grows.

Start with one demo conversation, then create an API key when the support flow is worth testing in your product.

GET STARTED WITH AIPOWER

16 AI models. One API. OpenAI SDK compatible.

Who should use AIPower?

  • • Developers needing both Chinese and Western AI models
  • • Chinese teams that can't access OpenAI / Anthropic directly
  • • Startups wanting multi-model redundancy through one API
  • • Anyone tired of paying grey-market intermediary premiums

3 steps to first API call

  1. Sign up — email only, 10 trial calls, no card
  2. Copy your API key from the dashboard
  3. Change base_url in your OpenAI SDK → done
from openai import OpenAI

client = OpenAI(
    base_url="https://api.aipower.me/v1",  # ← only change
    api_key="sk-your-aipower-key",
)

response = client.chat.completions.create(
    model="auto-cheap",   # or anthropic/claude-opus, deepseek/deepseek-chat, openai/gpt-5, etc.
    messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)

+100 bonus calls on first $5 top-up · WeChat Pay + Alipay + card accepted · docs · security