Build a Simple Q&A Chatbot for Your Website with Cohere
Set up a basic AI assistant on your business site using Cohere's powerful models and a simple copy-paste code snippet, perfect for answering common customer questions.
By the end of this guide, you’ll have a basic chatbot on your website that can answer your most common customer questions. This approach uses Cohere's powerful artificial intelligence (AI) models and requires a simple copy-paste of some code onto your website, making it accessible even if you're new to coding. This chatbot can draft responses, but it won't process payments or manage complex user accounts without further development.
💡 Tip: tap a step’s number when you finish it — a green tick appears and your browser remembers how far you got.
- Cohere Account: A free or paid Cohere account. The steps in this guide work with a free plan, though paid plans offer higher usage limits.
- Website Access: You need administrative access to your website to add custom HTML (HyperText Markup Language) or JavaScript code. This is typically available through platforms like WordPress, Wix, Squarespace, or Shopify.
- Common Questions: A short list of the top 3-5 questions your customers frequently ask, along with your desired answers.
- Time: Allocate about 30-45 minutes to follow these steps and test your new chatbot.
Create or Log In to your Cohere Account
First, open your web browser and go to the Cohere website at cohere.com. Look for a Sign Up or Log In button, usually in the top-right corner. If you're new, follow the prompts to create your account, which will involve verifying your email address. If you already have an account, simply log in with your credentials.
You'll know it worked when you see the Cohere console or dashboard after successfully logging in, which usually displays options like "Playground," "Models," or "API Keys."

Find Your API Keys and Playground
Once logged in, you'll need two main things: an API key and access to the Playground. An API key is like a secret password that lets your website talk to Cohere's AI services, and the Playground is where you can test how Cohere's AI models respond. Navigate your dashboard to find "API Keys" and "Playground" (or similar names). A new screen will open, showing your existing API keys or an option to create a new one. Click on Create New Key if you don't have one, and give it a memorable name like "MyChatbotKey." Then, switch to the "Playground" section. If you can't find these options directly, look for a left-hand navigation menu or a "Developers" section. You'll know it worked when you have a long string of letters and numbers (your API key) copied to your clipboard or saved safely, and you're on a page with a text input box labelled "Prompt" in the Cohere Playground.

Craft Your Chatbot's Responses in the Playground
In the Cohere Playground, you can teach the AI how to respond to specific questions. A prompt is the instruction or question you give to the AI, and the response is the answer it generates. For a simple Q&A chatbot, you'll provide specific instructions for common questions. Type your first question into the "Prompt" box. After typing your prompt, click the Run or Generate button, usually found below the prompt box. The AI will then generate a response in the output area. You can adjust your prompt or the AI's settings (like "Temperature" or "Max Tokens" which control creativity and length) until you get the perfect answer for your chatbot.
If the response isn't what you expect, try rephrasing your prompt with more detail. You'll know it worked when the AI generates a clear, helpful response that you'd like your chatbot to give customers for that specific question.

Prepare the Chatbot's Logic with a Simple Code Snippet
Now, you need a small piece of JavaScript code that will connect your website to Cohere's API and display your chatbot. This code will act as a digital messenger, sending customer questions from your site to Cohere and bringing back the AI's answers. You'll need your Cohere API key from Step 2.
Open a plain text editor (like Notepad on Windows or TextEdit on Mac, or any code editor) and copy-paste the following basic JavaScript snippet into it. Replace "YOUR_COHERE_API_KEY" with the API key you saved earlier, and feel free to adjust the welcomeMessage or botName. This snippet creates a simple chat interface and makes a request to Cohere's Chat API.
<script>
const chatbotContainer = document.getElementById('ai-world-chatbot');
chatbotContainer.innerHTML = `
<div style="position: fixed; bottom: 20px; right: 20px; width: 300px; height: 400px; border: 1px solid #ccc; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); display: flex; flex-direction: column; background-color: white; z-index: 1000;">
<div style="background-color: #007bff; color: white; padding: 10px; border-top-left-radius: 8px; border-top-right-radius: 8px;">
<h3 style="margin: 0;">My Shop Helper</h3>
</div>
<div id="chat-messages" style="flex-grow: 1; padding: 10px; overflow-y: auto; background-color: #f9f9f9;">
<p><strong>Bot:</strong> Hello! How can I help you today?</p>
</div>
<input type="text" id="chat-input" placeholder="Type your message..." style="padding: 10px; border: none; border-top: 1px solid #eee; border-bottom-left-radius: 8px; border-bottom-right-radius: 8px;">
</div>
`;
const chatMessages = document.getElementById('chat-messages');
const chatInput = document.getElementById('chat-input');
const COHERE_API_KEY = "YOUR_COHERE_API_KEY"; // Replace with your actual Cohere API Key
async function sendMessageToCohere(message) {
const response = await fetch("https://api.cohere.ai/v1/chat", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${COHERE_API_KEY}`
},
body: JSON.stringify({
message: message,
model: "command-r-plus", // You can choose a different model
// Add more context or conversation history here for a smarter bot
})
});
const data = await response.json();
return data.text;
}
chatInput.addEventListener('keypress', async function(e) {
if (e.key === 'Enter' && chatInput.value.trim() !== '') {
const userMessage = chatInput.value.trim();
chatMessages.innerHTML += `<p><strong>You:</strong> ${userMessage}</p>`;
chatInput.value = '';
const botResponse = await sendMessageToCohere(userMessage);
chatMessages.innerHTML += `<p><strong>Bot:</strong> ${botResponse}</p>`;
chatMessages.scrollTop = chatMessages.scrollHeight; // Auto-scroll to latest message
}
});
</script>
If this snippet looks different from Cohere's official documentation in the future, always use the most up-to-date example from Cohere's developer resources. You'll know it worked when you have your customised code snippet, including your API key, saved in a plain text file.

Add the Code Snippet to Your Website
Now it's time to add your chatbot to your live website. You'll need to paste the code snippet you prepared in Step 4 into the HTML of your website. Most website platforms, or CMS (Content Management Systems) like WordPress, Shopify, or Wix, have a way to add custom code. Look for options such as "Custom HTML," "Theme Editor," "Code Injection," or "Embed Code."
Paste the entire snippet (starting with <div id="ai-world-chatbot"> and ending with </script>) just before the closing </body> tag of your website's HTML. This ensures the chatbot loads correctly after all your site's content. Save your changes and publish your website.
If you're using a CMS like WordPress, you might use a plugin for custom code, or navigate to Appearance > Theme File Editor > footer.php. On Shopify, go to Online Store > Themes > Actions > Edit code > theme.liquid. Look for the </body> tag and paste your code above it.
You'll know it worked when you've saved and published your website changes, and there are no immediate error messages from your CMS.

Test Your Chatbot
With the code now live on your website, it's time to test if your chatbot is working correctly. Open your website in a fresh browser window or tab. You should see a small chat bubble or a simple chat window appear, usually in the bottom-right corner of your screen, based on the basic styling in our snippet. Click on the chat window to open it and type in one of the common questions you prepared in Step 3. Press Enter. The chatbot should send your message to Cohere and display an AI-generated response shortly after. If the chat window doesn't appear, try clearing your browser's cache and reloading the page, or double-check your website's custom code area for any typos. You'll know it worked when you can type a question into the chat window on your website and receive a relevant AI-generated response back.

- Incorrect API Key: Forgetting to replace
"YOUR_COHERE_API_KEY"with your actual key, or using an expired/incorrect one. Always double-check your API key and ensure it's active in your Cohere dashboard. - Wrong Placement of Code: Placing the JavaScript snippet inside the
<head>tag or in a part of your website that isn't rendered properly can prevent the chatbot from appearing. Always aim for just before the</body>tag for client-side scripts. - Not Publishing Changes: After adding code to your website's editor, you must save and publish the changes for them to go live. Many beginners forget this final step in their CMS.
Revisit your Cohere Playground and experiment with refining a prompt to give an even better answer to a common customer query, like "What are your business hours?". Make sure your custom JavaScript snippet on your website is still open in your text editor. Then, on your live website, open the chatbot and ask that question to see your AI in action.
❓ Quick questions
How long does this take?
About 7 minutes — the guide has 6 steps, and you can tick each one off as you go.
Which tool do I need?
This guide uses Cohere Cohere — but the approach works very similarly in other AI assistants.
Do I need to prepare anything?
- Cohere Account: A free or paid Cohere account. The steps in this guide work with a free plan, though paid plans offer higher usage limits.
- Website Access: You need administrative access to your website to add custom HTML (HyperText Markup Language) or JavaScript code. This is typically available through platforms like WordPress, Wix, Squarespace, or Shopify.
- Common Questions: A short list of the top 3-5 questions your customers frequently ask, along with your desired answers.
- Time: Allocate about 30-45 minutes to follow these steps and test your new chatbot.
What mistakes should I avoid?
- Incorrect API Key: Forgetting to replace
"YOUR_COHERE_API_KEY"with your actual key, or using an expired/incorrect one. Always double-check your API key and ensure it's active in your Cohere dashboard. - Wrong Placement of Code: Placing the JavaScript snippet inside the
<head>tag or in a part of your website that isn't rendered properly can prevent the chatbot from appearing. Always aim for just before the</body>tag for client-side scripts. - Not Publishing Changes: After adding code to your website's editor, you must save and publish the changes for them to go live. Many beginners forget this final step in their CMS.
Keep reading
📬 The week’s AI, in your inbox
One friendly email every Sunday — the 5 stories that mattered, in plain English. No spam, unsubscribe anytime.
✦ Original step-by-step guide by AI World HQ's AI editorial team. Written in plain language, reviewed for accuracy.
← Back to all stories