AI Chatbot API for Website Use Without Leaking Your Key: The Server Proxy Pattern, the Checks It Needs and a Page Leak Checker (Free Tool)
AI chatbot API for website projects often start with a tutorial that puts the API key straight into page JavaScript. Within days, someone can copy the key from View Source and run their own app on your bill. This guide shows the three ways an AI API can reach a website, why only two of them are safe, what a small server proxy must check, and how to scan your own page for a leaked key in a minute.
⚡ In short
- Anything in your page’s JavaScript can be read by every visitor, including an API key.
- Never call an AI provider straight from the browser with a real key. Send the chat to your own server, and let it call the provider.
- The server should limit messages per visitor, check where requests come from, cap message length and history, and stop at a monthly budget.
- A hosted chat widget keeps its AI key on the vendor’s servers, so there is nothing to leak from your page.

The problem
Why the key can’t live in your page
Your website is public code. Every visitor’s browser downloads every script, and developer tools show every network request with its headers.
So if page JavaScript sends a request to an AI provider with an Authorization header holding your key, the key is visible to anyone who looks. Automated scrapers look for exactly these patterns. A copied key can be used from anywhere, for anything, until you revoke it, and the bill comes to you.
This is the most common mistake in do-it-yourself AI chatbot API for website setups, because quick tutorials skip it to keep the example short.
If you have a developer, ask them one question: “Where does the AI key live?” The only good answers are “on our server” or “with the chat vendor”. Our source code review checklist has a dozen more checks for any bot code you copy.
Three architectures
Three ways to wire an AI chatbot API for website chat
| Setup | Where the key lives | Safe? | Who builds it |
|---|---|---|---|
| Browser calls the AI provider directly | In page JavaScript | No | Quick tutorials |
| Browser calls your server, server calls the provider | On your server only | Yes, with checks | You or your developer |
| Hosted chat widget with built-in AI | On the vendor’s servers | Yes | The vendor |
The proxy pattern
Five steps for the do-it-yourself route
1
Widget sends the message to you
The page posts the visitor’s message to an address on your own domain, such as /chat. No key in the page.
2
Server checks the request
Is it from your site? Is this visitor within their limit? Is the message a sensible length?
3
Server adds the secret parts
Your instructions, the knowledge snippet and the API key are added on the server, never sent to the browser.
4
Server calls the provider
It forwards a trimmed history and waits for the reply.
5
Server returns only the answer
The browser gets the reply text. Nothing else.
Free tool
Scan your page for a leaked AI key
Paste your page source or chatbot script. The checker finds common AI key formats, direct calls to AI providers from the browser and risky settings, and tells you what to fix first.
Paste your page source or the chatbot JavaScript (View Source in your browser, or the script file your developer added). The checker looks for AI keys and direct provider calls that visitors could copy.
Runs only in your browser; nothing is sent or saved. Found keys are shown masked. The example contains a fake key.
Server checks
What your proxy must check on every message
Moving the key to a server stops it being copied, but your proxy is now a public address that spends your money. Treat it like a payment form.
Rate limit per visitor
Allow, say, 30 messages per visitor per hour. Real customers rarely hit it; scripts do.
Check the origin
Accept requests only from your own domain. It stops casual reuse.
Cap message and history length
Reject very long messages and send only the last six to eight turns.
Keep the bot on topic
Tell the model to answer only about your business, or your site becomes a free general chatbot.
Set a monthly budget
Count spend yourself and set a provider cap. When it runs out, return a fixed message and a contact option. Our API pricing stress test helps you pick the number.
If a key has leaked
Fix it in this order
If the checker found a key, act today, even if your bill looks normal.
- Revoke the key in your provider's dashboard. Deleting it from the page is not enough; copies already exist.
- Check usage for odd hours or models you never use.
- Create a new key and store it only on the server, in an environment variable, not in a file inside your public web folder.
- Set a spending cap.
- Search backups and public repositories for the old key.
Then move the chat to a proxy or a hosted widget. Never put the new key back in the page "just for now".
The hosted route
When you don't want to run a server at all
Running a proxy means owning a server, patching it and handling abuse. A hosted chat widget avoids all of that: you paste one script tag, and the vendor's servers hold the AI key and do the checks.
That is how LiveChatBot works. The AI Agent answers from the knowledge you give it, runs on LiveChatBot's servers, and stops at a small free monthly allowance per website or the AI packs you buy, with no automatic charges. Abusive visitors can be blocked by visitor or IP. If you are a developer, the JavaScript API (window.LiveChatBot) lets you open, hide or pre-fill the widget from your own code, and the REST API and webhooks connect tickets to your systems; see integrations and ask our team for developer documentation.
What it does not do: you can't bring your own AI key or pick the model. If you need that control, an AI chatbot API for website use through your own proxy is the right choice, with every check above in place.
Checklist
Before your bot goes live
Frequently asked questions
Can I call an AI chatbot API for website chat straight from JavaScript?
Only with a short-lived token issued by your own server. With a real API key, no: every visitor can read it from the page source or network tab.
Is hiding the key in a separate .js file safe?
No. The browser downloads that file too, so anyone can open it. The key must stay on a server.
What should I do if my key was in the page?
Revoke it in the provider dashboard, check recent usage, create a new key on the server only and set a spending cap.
Does a hosted widget expose any key?
A well-built one doesn't. LiveChatBot's embed script only identifies your website; the AI runs on LiveChatBot's servers.
Does the leak checker send my code anywhere?
No. It runs entirely in your browser and nothing is sent or saved.
Keep reading
Related guides
Chatbot API Pricing Guardrails: Stress-Test Your Bill Against Sales, Spam and Long Chats Before You Set a Cap (Free Bill Stress Tester)
AI chat with no key on your page
Paste one script, add your knowledge and let the AI Agent answer, with a free keyword bot as the fallback. Start free on livechatbot.in.