• Product Introduction
  • Quick Start
    • Agent Development
    • Importing a Git Repository
    • Starting From a Template
    • Direct Upload
    • Start with AI
  • Framework Guide
    • Agent
    • Frontends
      • Vite
      • React
      • Vue
      • Hugo
      • Other Frameworks
    • Backends
    • Full-stack
      • Next.js
      • Nuxt
      • Astro
      • React Router
      • SvelteKit
      • TanStack Start
      • Vike
    • Custom 404 Page
  • Project Guide
    • Project Management
    • edgeone.json
    • Configuring Cache
    • Building Output Configuration
    • Error Codes
  • Build Guide
  • Deployment Guide
    • Overview
    • Create Deploys
    • Manage Deploys
    • Deploy Button
    • Using Github Actions
    • Using Gitlab CI/CD
    • Using CNB Plugin
    • Using IDE PlugIn
    • Using CodeBuddy IDE
  • Domain Management
    • Overview
    • Custom Domain
    • HTTPS Configuration
      • Overview
      • Apply for Free Certificate
      • Using Managed SSL Certificate
    • Configure DNS CNAME Record
  • Observability
    • Overview
    • Metric Analysis
    • Log Analysis
  • Functions
    • Overview
    • Edge Functions
    • Cloud Functions
      • Overview
      • Node.js
      • Python
      • Go
  • Agents
    • Overview
    • Quick Start
    • Conversation Storage
    • Observability
    • Sandbox Tool
      • Overview
      • Using the Agent Framework
      • Sandbox Atomic API
      • Network Search Tool
    • Agent Authentication
  • Models
    • Overview
    • Models and Vendors
      • Overview
      • Using Vendor Keys
        • OpenAI
        • Anthropic
        • Google AI Studio
        • DeepSeek
        • MiniMax
        • Hunyuan
        • Zhipu
        • MoonShot AI
    • FAQs
  • Storage
    • Overview
    • KV
    • Blob
  • Middleware
  • AI-Native Development
    • Skills
    • MCP
  • Copilot
    • Overview
    • Quick Start
  • API Token
  • EdgeOne CLI
  • Message Notification
  • Integration Guide
    • AI
      • Dialogue Large Models Integration
      • Large Models for Images Integration
    • Database
      • Supabase Integration
      • Pages KV Integration
    • Ecommerce
      • Shopify Integration
      • WooCommerce Integration
    • Payment
      • Stripe Integration
      • Integrating Paddle
    • CMS
      • WordPress Integration
      • Contentful Integration
      • Sanity Integration
      • Payload Integration
    • Authentication
      • Supabase Integration
      • Clerk Integration
  • Best Practices
    • Adding an AI Chat Assistant to a Website
    • AI Dialogue Deployment: Deploy Project with One Sentence Using Skill
    • Using General Large Model to Quickly Build AI Application
    • Use the DeepSeek model to quickly build a conversational AI site
    • Building an Ecommerce Platform with Shopify
    • Building a SaaS Site Using Supabase and Stripe
    • Building a Company Brand Site Quickly
    • How to Quickly Build a Blog Site
  • Migration Guides
    • Migrating from Vercel to EdgeOne Pages
    • Migrating from Cloudflare Pages to EdgeOne Pages
    • Migrating from Netlify to EdgeOne Pages
  • Troubleshooting
  • FAQs
  • Limits
  • Pricing
  • Contact Us
  • Release Notes

Adding an AI Chat Assistant to a Website

This document describes how to use the AI Assistant template to add an AI-powered conversational assistant to your website. With just a single line of embedded code, the AI can automatically understand your page content, query your business APIs, and answer user questions in real time.
You will receive:
An out-of-the-box AI conversation Widget (bubble + chat panel).
Automatically extract the content of the current page for use as AI context.
Enable the AI to query your backend data in real time via an API Schema.
It can be embedded into any website (such as blogs, e-commerce sites, documentation sites, and admin dashboards).

Effect Preview

Users see a chat bubble on your website and, upon clicking it, open a conversation panel.
When a user asks "What is this article about?", the AI responds based on the page content.
When a user asks "Help me search for React-related articles", the AI calls your search API and returns real data.
When a user asks "What are the details of the third article?", the AI calls the details API to obtain the full text.

Prerequisites

1. Your website (any framework: React, Vue, WordPress, static HTML, and so on).
2. (Optional) Your backend API address, if the AI needs to query business data.

Quick Start

1. Deploying the Agent

Start deployment directly using the sample template below.

On the deployment configuration page, fill in the environment variables (see Step 2 below).

2. Configuring Environment Variables

On the deployment configuration page (or after deployment, go to the project → SettingsEnvironment Variables), fill in the following configurations:
Variable
Required
Description
AI_GATEWAY_MODEL
Model ID, default @makers/deepseek-v3
DATA_API_BASE_URL
The root URL of your backend API, for example, https://api.example.com
DATA_API_KEY
Backend authentication Token (added to the Authorization: Bearer header of the request)
Note: AI_GATEWAY_API_KEY and AI_GATEWAY_BASE_URL are automatically injected during one-click deployment.

3. Binding a Custom Domain

Go to the EdgeOne Makers console → your project → Domain Management, and bind your own domain, for example: chat.example.com.
Note: After a custom domain is bound, it can be accessed without any authentication, which is a prerequisite for formal use.

4. Embedding into Your Website

Add a line of code in your website's HTML, before </body>:
<script src="https://chat.example.com/embed.js" async></script>
Refresh the page. A chat bubble appears in the lower-right corner. Click it to start a conversation. Done!

Customizing the Appearance

Customize the appearance of the chat bubble through the data-* attribute:
<script
src="https://chat.example.com/embed.js"
data-color="#10b981"
data-position="bottom-left"
data-name="Assistant"
async>
</script>
Required
Default Value
Description
data-color
#6366f1
Primary color (bubbles, buttons, avatar backgrounds)
data-position
bottom-right
Bubble position: bottom-right or bottom-left
data-name
AI Assistant / AI Assistant
Name displayed at the top of the chat panel

Customizing System Prompts and Suggested Questions

Edit the ai-chat-assistant.config.json file in the project root directory:
{
"name": "My Assistant",
"welcome": "Hello! How can I help you?",
"systemPrompt": "You are a professional e-commerce customer service assistant. Provide concise and friendly responses, and prioritize recommending store products.",
"suggestedQuestions": [
"What are the popular products?",
"How do I check the order status?",
"What is the return and exchange policy?",
]
}
Field
Description
name
Name displayed at the top of the chat panel
welcome
Welcome message displayed upon first opening
systemPrompt
AI system prompt that determines the AI's behavior style.
suggestedQuestions
List of suggested questions that users can directly click to send.
After making modifications, push the code or redeploy for the changes to take effect.

API Schema Details

endpoint Path Rules

The {param} in the path is replaced by the parameter value with the same name: GET /api/posts/{id} + {"id": "5"}GET /api/posts/5.
Parameters not used for path replacement:
For a GET request, it is used as a query string: GET /api/posts?q=react.
For POST/PUT requests, the content is sent as a JSON body.

description Writing Tips

The description determines when the AI calls your API, and how well it is written directly impacts the effectiveness:
// ❌ Too vague
"description": "Retrieve data"

// ✅ Clearly states the feature + usage scenario
"description": "Get the full content of a single blog post by its ID. Use search_posts first if you don't know the ID."

backend Cross-Origin Requirements

The Agent will send requests to your backend from the EdgeOne domain, so you need to configure CORS on your backend:
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Headers: Content-Type, Authorization

Embedding in Different Frameworks

React / Next.js

useEffect(() => {
const s = document.createElement('script');
s.src = 'https://chat.example.com/embed.js';
s.async = true;
document.body.appendChild(s);
return () => document.body.removeChild(s);
}, []);

Vue

<script setup>
import { onMounted } from 'vue'
onMounted(() => {
const s = document.createElement('script')
s.src = 'https://chat.example.com/embed.js'
s.async = true
document.body.appendChild(s)
})
</script>

WordPress

Add the following before </body> in the theme's footer.php file:
<script src="https://chat.example.com/embed.js" async></script>

Static HTML

Simply add it directly before </body>, with no build tools required.

How It Works

Users ask questions on your website.
embed.js injects a chat bubble + iframe (which loads the same-origin /widget).
Page content is extracted via embed.js and sent to the iframe using postMessage.
┌─────────────────────────────────────────┐
│ The /widget page (same-origin) within the iframe │
│ │
│ fetch('/chat') → processed by the Agent: │
1. Inject page content into the AI context │
2. The AI determines whether it needs to call the backend API │
3. If needed → call your API → retrieve data │
4. The AI generates a response based on all the information │
5. The SSE stream is returned to the frontend │
└─────────────────────────────────────────┘
Users see the response generated in real time.

Why use an iframe? The iframe loads the /widget page, which is in the same domain as the Agent. All API requests within it are same-origin, eliminating cross-origin issues.

Local Debugging

# Clone your repository.
git clone https://github.com/your-username/ai-assistant.git
cd ai-assistant

# Install dependencies.
npm install

# Configure environment variables.
cp .env.example .env
# Edit the .env file and populate it with AI_GATEWAY_API_KEY and other variables.

# Start the development server.
edgeone makers dev

Environment Variables

Variable
Required
Description
AI_GATEWAY_API_KEY
AI model API Key
AI_GATEWAY_BASE_URL
Model gateway address
AI_GATEWAY_MODEL
Model ID, default @makers/deepseek-v4-flash
DATA_API_BASE_URL
Your backend API root URL
DATA_API_KEY
Backend authentication Token
Note: Modify configurations such as assistant name, welcome message, system prompts, and suggested questions in the ai-assistant.config.json file in the project root directory.

FAQs

Q: Can I use it if my backend is not on EdgeOne?
Yes. Your backend can be deployed on any location with a public network address (such as AWS, Alibaba Cloud, or a self-built server). You only need to set the DATA_API_BASE_URL to point to your backend address.
Q: Can it be used without configuring api-schema.json?
Yes, it works. When not configured, the AI only answers questions based on the content of the current page and does not call any external APIs.
Q: Will the AI call APIs not defined in the schema?
No. The AI can only call APIs explicitly defined in api-schema.json and will not construct other requests on its own.
Q: Which models are supported?
It supports all OpenAI-compatible model APIs, including DeepSeek, GPT-4o, Claude, Qwen, and others. You only need to modify the AI_GATEWAY_BASE_URL and AI_GATEWAY_API_KEY.
Q: How does embed.js support Single-Page Applications (SPAs)?
Yes. The script automatically detects URL changes and re-extracts page content to send to the AI when routing switches.
Q: How can I limit the AI call frequency?
Implement rate limiting on your backend. The Agent can call tools a maximum of 4 times per conversation round.
ai-agent
You can ask me like
What types of applications can I deploy?