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. The safe pattern, recommended by OpenAI, Google and Anthropic alike, is to keep the key on your server and have the browser call your own endpoint, which checks the request before passing it on. Add a monthly spending limit and a separate key for each site, and make a backup before you start. This article explains each step and what to do if a key leaks.
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. OpenAI's guidance is blunt: never deploy your key in client-side environments like browsers or mobile apps, because anyone who finds it can make requests on your behalf. Google says the same about its Gemini keys.
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.
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:
The providers give you controls that turn a leak from a disaster into a nuisance:
Keep the key 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: an environment variable, a constant in wp-config.php, then the key saved through the Connectors screen. The WordPress developers note that keys saved through the screen are masked in the interface but are not encrypted in the database. Because the database goes into every backup and export, putting the key in an environment variable or in wp-config.php is the better choice where you can.
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.
Before you install an AI plugin or deploy new code:
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.