An AI API key works like a credit card number: whoever has it can run up charges on your account. If you put it in your website's JavaScript, every visitor can read it. To keep an API key out of the browser, hold it on your server and let the browser call your own endpoint, which checks each request before passing it on, as OpenAI, Google and Anthropic all recommend.
In short
Anyone who finds the key can spend your money with it. When you add a chatbot, a writing helper or a product-description generator to a website, the AI service needs a key to know who to bill. Anthropic compares a key to a credit card number. Google says the same about its Gemini keys, and OpenAI's guidance is blunt:
"Never deploy your key in client-side environments like browsers or mobile apps."
OpenAI adds the reason: anyone who finds the key can make requests on your behalf.
Hiding the key does not help. Minified, encoded or split-up text in a web page can still be read by anyone who opens the browser's developer tools.
| Route | What happens |
|---|---|
| Page source | A key in front-end JavaScript is visible to every visitor. |
| Public code repositories | Anthropic names keys committed to public GitHub repositories as a common leak. GitHub scans public repositories for known key formats and reports them to the provider; Anthropic says it then deactivates an exposed Claude key automatically and emails you. Do not rely on that as your protection. |
| Pasted into other tools | Anthropic warns that giving a key to a third-party tool gives that tool's developer access to your account. |
| Backups and exports | A key saved in a website's database travels with every copy of that database. |
Your server holds the key. The browser never talks to the AI provider. It talks to an endpoint on your own website, and your server, which holds the key, calls the provider.
That endpoint must do more than pass messages along, or it becomes an open door that spends your money. The OWASP Foundation lists "unbounded consumption", including attackers deliberately running up your bill, among the top risks for AI applications. So the endpoint should do five things:
Use the controls the providers give you. They turn a leak from a disaster into a nuisance.
| Control | What it does |
|---|---|
| One key per site or feature | Each key sits in its own project (OpenAI) or workspace (Anthropic), so you can revoke one without breaking the rest. |
| A monthly spending limit with hard enforcement | OpenAI notes that spending alerts alone do not stop traffic, and that enforcement may lag slightly, so set the limit with a margin. |
| Separate keys for development, testing and the live site | A mistake in testing cannot touch the live key. |
| Expiry and rotation | OpenAI lets project keys expire; Anthropic suggests rotating, for example every 90 days. |
| IP allowlisting, where offered | The key only works from your server's address. |
Where the key is stored matters too. Keep it in an environment variable or a configuration file outside the website's public folder, never in code you commit. The OWASP secrets guidance adds a caution: environment variables can end up in logs or error dumps, so do not print them.
WordPress 7.0, released in May 2026, added an AI Client and a Connectors screen under Settings for Anthropic, Google and OpenAI. AI requests made through it run on the server, so the key never reaches visitors' browsers. Core WordPress ships no AI providers itself; each provider is a separate plugin.
WordPress looks for a connector's key in three places, in this order:
| Order | Where the key is read from | Note |
|---|---|---|
| 1 | An environment variable | The better choice where you can use it. |
| 2 | A constant in wp-config.php |
The better choice where you can use it. |
| 3 | The key saved through the Connectors screen | Masked in the interface but not encrypted in the database. |
Why the first two are better. The database goes into every backup and export, so a key saved through the screen travels with each copy. An environment variable or a constant in wp-config.php stays out of it.
Premium shared hosting has what you need to start:
Legacy hosting has no SSH, so a custom endpoint there would be a WordPress plugin rather than a separate app. For a larger AI back end, a Noiz Cloud server gives you full root access on a server of your own.
Do three things before you install an AI plugin or deploy new code:
Revoke the key before anything else, then work through the rest.
Read next:
Premium shared hosting gives developers SSH access to their own hosting account, a dedicated PHP pool and WP Toolkit to build AI features the safe way, and every plan includes a weekly backup kept off site. If you would rather not maintain WordPress yourself while you add new features, WordPress Care keeps it updated weekly with a restore point taken first.
Checked 19 October 2026.
AI providers
Security guidance
WordPress
Noiz
Note: while some of this content was produced with the help of AI, the final editing has been done by a real human being.