Add Sem to your website
A step-by-step guide to putting Sem, the voice assistant, on your website so it answers your visitors from your own website's content, and to keeping your keys safe.
- Before you start
- Know your keys: which are public, which are secret
- Create an assistant for your website
- Limit it to your own website
- Give it your website's content
- Set its character and instructions
- Add the code to your website
- Keep secret keys in a .env file
- Test it
- If a key is exposed
- Security checklist
- Troubleshooting
Before you start
- A Console.semdok account. Sign in at console.semdok.com; every sign-in needs the code we email you.
- A paid plan (Starter, Pro or Max). Visitors' conversations with Sem on your website use your plan's voice hours: Starter 10 hours a month, Pro 30, Max 100. The Free plan has no voice hours for website assistants.
- Access to edit your website's pages (HTML, WordPress, Shopify theme, or your web app's code).
- Your website must use HTTPS. Browsers only allow the microphone on secure pages.
Know your keys: which are public, which are secret
Console.semdok gives you three kinds of keys. Only one of them may ever appear in your web pages.
| Key | Looks like | Where it goes | Can visitors see it? |
|---|---|---|---|
| Assistant key (public) | sem_pub_live_… | In your web page, inside the Sem embed code | Yes, by design |
| Semdok API key (secret) | sk-… | Only on your server, in a .env file | Never |
| Sem API key (secret) | sem_sk_… | Only in the Sem app, Semdok Harness, or your server's .env | Never |
sk-… and sem_sk_…) must never be in a web page, in JavaScript that runs in the browser, in a mobile app, or in a public code repository. Anyone who gets one can use it as you: spend your tokens and voice hours, and send their own instructions and questions in your name, so the answers can have nothing to do with your website and can be made to say whatever they want. Keep them in a .env file on your server (step 6).1Create an assistant for your website
- Sign in to console.semdok.com and open SEM Assistant in the sidebar.
- Click New assistant and give it a name, for example "Acme website". Each assistant has its own key, character, allowed websites and knowledge, so you can have a different assistant for each of your websites.
- Under Assistant API key, you see its public key (
sem_pub_live_…). You don't need to copy it yet: it is already inside the embed code in step 5.
2Limit it to your own website
- In the assistant's settings, find Allowed websites.
- Enter your website's addresses, separated by commas, for example:
https://www.acme.com, https://acme.com, https://*.acme.com - Click Save. This list tells Sem which websites your assistant belongs to, so a copied embed code can't use your assistant (or your voice hours) on someone else's site.
* (any website) once your site is live. * is only for testing.3Give it your website's content
- On the same page, under Assistant Knowledge Base, choose Fetch from a website.
- Enter your website's address and keep Also fetch linked pages of the same site ticked (up to 20 pages per website, up to 10 websites).
- Click Fetch content. When it shows ready, click View content to see exactly what Sem read.
- Use Try a question to check: ask something your website answers, such as "What are your opening hours?", and see the passage Sem finds.
- When your website changes, click Refresh next to it so Sem reads the new version.
4Set its character and instructions
- In Character Customizer, choose the name, avatar, voice, theme and background, and write the greeting visitors hear first.
- In Instructions, tell Sem its job on your site, for example:
You are Sem, the assistant on acme.com. Answer only from Acme's website content. If the answer isn't there, say you don't know and suggest contacting support@acme.com. Be brief and friendly. Never discuss competitors or give medical or legal advice. - Click Save. The preview on the right shows how it looks.
5Add the code to your website
Copy the embed code from 1-line script tag for your website (the Copy Script button). It looks like this, with your own key:
<!-- Sem assistant -->
<script
src="https://live.semdok.com/widget/sem-widget.js"
data-assistant-brand="Acme website"
data-assistant-avatar="female"
data-assistant-theme="dark"
data-assistant-api-key="sem_pub_live_xxxxxxxxxxxxxxxx"
defer>
</script>
Paste it just before the closing </body> tag of every page where Sem should appear. A Sem button then appears in the corner of the page.
Optional settings
| Attribute | What it does |
|---|---|
data-assistant-position | Where the button sits, for example bottom-right or bottom-left |
data-assistant-trigger-label | The button's text, for example Ask Sem |
data-assistant-greeting | A greeting for this page only (otherwise the one from step 4) |
data-auto-open | true opens Sem when the page loads |
On popular platforms
- Plain HTML: paste the code before
</body>in each page (or in your shared footer). - WordPress: use a "header and footer code" plugin and paste the code into the footer box, or add it to your theme's
footer.phpbefore</body>. - Shopify: Online Store → Themes → Edit code → layout/theme.liquid, paste before
</body>, save. - Wix / Squarespace / Webflow: add it as custom code in the site's footer or before </body> setting, for all pages.
- React / Next.js: load the same script once in your layout. Only the public assistant key may be used here:
// app/layout.tsx (Next.js) import Script from "next/script"; export default function RootLayout({ children }) { return ( <html lang="en"> <body> {children} <Script src="https://live.semdok.com/widget/sem-widget.js" data-assistant-brand="Acme website" data-assistant-api-key={process.env.NEXT_PUBLIC_SEM_ASSISTANT_KEY} strategy="afterInteractive" /> </body> </html> ); }Only the public assistant key (sem_pub_live_…) may go in aNEXT_PUBLIC_,VITE_orREACT_APP_variable. Those variables are copied into the code every visitor downloads. Never put ansk-…orsem_sk_…key in them.
6Keep secret keys in a .env file
You only need a secret key if your own server also calls Semdok, for example to add an AI feature to your site through the Semdok API (https://console.semdok.com/v1). The website widget itself never needs one.
1. Put the key in a .env file on your server
# .env (on your server only — never commit this file)
SEMDOK_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxx
SEMDOK_BASE_URL=https://console.semdok.com/v1
2. Keep the file out of your code repository
# .gitignore
.env
.env.*
!.env.example
Commit a .env.example with the variable names but no values, so others know what to set. On hosting platforms (Vercel, Netlify, Render, a VPS…), enter the key in the platform's Environment variables settings instead of a file.
3. Read it only in server code
Your browser code calls your server; your server adds the key and calls Semdok. The key never reaches the visitor.
// server.js (Node.js + Express)
import "dotenv/config"; // loads .env
import express from "express";
import rateLimit from "express-rate-limit";
const app = express();
app.use(express.json({ limit: "20kb" }));
app.use("/api/ask", rateLimit({ windowMs: 60_000, max: 20 })); // stop abuse of your quota
app.post("/api/ask", async (req, res) => {
const question = String(req.body?.question || "").slice(0, 1000);
const r = await fetch(`${process.env.SEMDOK_BASE_URL}/chat/completions`, {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.SEMDOK_API_KEY}`, // the key stays on the server
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "auto/best-chat",
messages: [
{ role: "system", content: "You are the assistant for acme.com. Answer only about Acme." },
{ role: "user", content: question }
]
})
});
const data = await r.json();
res.json({ answer: data.choices?.[0]?.message?.content ?? "" }); // never send the key back
});
app.listen(3000);
# Python (FastAPI) — same idea
import os, httpx
from dotenv import load_dotenv
load_dotenv() # reads .env
KEY = os.environ["SEMDOK_API_KEY"] # never hard-code it
.env on your server, and only there, is what prevents this.Test it
- Open your website in a normal browser window (over HTTPS) and click the Sem button.
- Allow the microphone when the browser asks.
- Ask something your website answers, and something it doesn't. Sem should answer the first from your content and, for the second, say it doesn't know (following your instructions).
- In Console.semdok, open Cost & Compute: Sem voice this month shows the voice hours used so far.
- View your page's source (right-click → View page source) and search for
sk-andsem_sk_. Neither may appear anywhere.
If a key is exposed
- Revoke it straight away in Console.semdok: API Keys for
sk-…, SEM Assistant → Sem API keys forsem_sk_…. A revoked key stops working at once. - Create a new key and put it in your
.env(or your host's environment variables), then restart your server. - If an assistant key is being misused on another site, set Allowed websites (step 2). If you want a fresh key, create a new assistant and replace the embed code, then delete the old assistant.
- If the key was in a code repository, removing it from the latest version isn't enough — it stays in the history. Treat it as exposed and revoke it.
- Check your usage in Console.semdok and contact support@semdok.com if you see use you don't recognise.
Security checklist
- Only the public assistant key (
sem_pub_live_…) is in my web pages. - Allowed websites lists only my own domains (not
*). - Secret keys (
sk-…,sem_sk_…) are only in.envor my host's environment variables. .envis in.gitignoreand has never been committed.- No secret key is in a
NEXT_PUBLIC_,VITE_orREACT_APP_variable, or in a mobile app. - My server routes that call Semdok have a rate limit.
- My Console.semdok sign-in email is one only I can read (every sign-in sends a code there).
- The assistant's instructions say what to do when the answer isn't on my website.
Troubleshooting
| What you see | What to do |
|---|---|
| No Sem button on the page | Check the code is before </body> on that page and that the page was published. If your site has a Content Security Policy, allow Sem: script-src https://live.semdok.com; frame-src https://live.semdok.com |
| Sem doesn't hear you | The page must be HTTPS, and the visitor must allow the microphone (the browser's address-bar icon). |
| Sem doesn't know your content | In SEM Assistant, check the website shows ready, use View content, and Refresh after changing your site. Make sure the embed code uses this assistant's key. |
| Sem stops working mid-month | Your plan's voice hours for the month are used up. They renew on your billing day, or upgrade in Subscriptions. |
| Works on your site but also on someone else's | Set Allowed websites (step 2). |
Still stuck? Email support@semdok.com with your website address and the assistant's name. Never send us a secret key.