htmlhost.co
Back to Guides
Platform Features

How to Use API Keys Safely on Your Website

Stripe, Mailchimp, Google Maps and Google Analytics all hand you keys. Save them once with your site, mention them by name when you ask AI to build something, and keep the secret ones out of your pages for good.

Public and secret keys

Every key you save has a kind. Choose it from what the service says about the key:

  • Public. For values a service says are safe to show: a payment gateway's public key, an analytics ID, a form address. Every visitor to a page can read what's written into it.
  • Secret. For values that must stay private: a secret or API key. Once saved it can be replaced but not read back, and it is never written into a page.

The difference matters because a website's files are public: anyone can open your page's source. A public key there is fine. A secret key there can be copied and used to act as you: issue refunds, read your customer list or send email from your account.

Save a key

  1. Open your dashboard, open the site, select Keys, then Add key. Keys are part of Pro: up to 50 per site.
  2. Give it a name, such as MAPS_API_KEY or MAILCHIMP_API_KEY, and paste the value.
  3. Check the kind, then select Add key. The form suggests one from the value (Stripe's pk_ publishable keys are public, its sk_ keys secret) and starts on Secret when it can't tell.

Build with a public key

AI Edit knows your keys by name:

“Add Google Analytics to every page with GA_MEASUREMENT_ID.”
“Show our office on a map on the contact page using MAPS_API_KEY.”

AI writes the key's name into the page, as {{key:GA_MEASUREMENT_ID}}, and htmlhost fills in the current value whenever it shows the page. So when you change the key later, save it in Keys and your live site uses the new value within about a minute. There's nothing to edit or republish.

Ask AI to build with a secret key

A secret key needs a secure call: a request htmlhost makes for your page, without exposing the key to visitors. You don't need to write that request yourself. Tell AI what the feature should do and which saved key to use.

“Add a newsletter sign-up to my site using MAILCHIMP_API_KEY. Ask me for the Mailchimp server and audience ID if you need them. Reuse a suitable secure call or create one, and show a clear success or error message after someone subscribes.”

AI Edit and connected CLI/MCP tools can prepare the page and create the call together. Review the service and key when asked. For Mailchimp, save the server value, such as us21, as MAILCHIMP_SERVER and the audience ID as MAILCHIMP_LIST_ID, both Public; keep MAILCHIMP_API_KEY Secret. AI uses these names, not your saved secret's value.

Have AI prepare a definition to paste

Prefer to review and add the call in your dashboard? Ask AI for its definition: a small JSON description of the request. This is also the path to use when your AI tool can write code but cannot create htmlhost calls directly. You can paste the definition instead of filling in the technical form field by field.

“Give me the htmlhost secure-call definition for this feature so I can paste it into my dashboard. Follow https://htmlhost.co/agents.md. Use my saved key names, never secret values. Return one JSON object per call, without Markdown code fences, and explain what visitors can send and what the page gets back.”
  1. Open your dashboard → open the site → Keys → Secure calls.
  2. Select Paste a definition, paste one JSON object from AI, then select Review call.
  3. Check the service address and key names, what visitors can fill in, the request body and what the page gets back. A price or other value visitors must not control should be fixed.
  4. Use Edit details to adjust the call, or Back to JSON to replace the definition. If a key is missing, add it in Keys above; your review stays open.
  5. Select Add call. If AI gave you several calls, repeat for each one. Tell AI which calls you added so it can finish the matching page code.

If the JSON is invalid, your text stays in place with an explanation. Ask AI to correct it and paste the replacement. If a call with that name already exists, edit the existing call or ask AI to reuse it.

Finish setup and test

  • Needs key: add the named key in the same Keys tab.
  • Off: select the call's switch, review its destination and keys, then select Enable call. Some calls created by connected tools wait for this dashboard approval.
  • Enabled: the call is switched on. This does not mean it has been tested.

Publish when you're ready, then try the feature on your published site. Secure calls do not run in the editor preview. Check both the success and error messages.

When an integration needs its own backend

Keys keep credentials with your site, and secure calls let pages make the requests you define. They do not add a general application backend. For these capabilities, connect the service your feature needs while keeping your website on htmlhost:

  • Visitor authentication and per-user permissions. A saved service key identifies the service account, not the visitor using your page. Secure calls do not verify visitor sessions or decide which user owns a record. For private account data, use Supabase Auth with database access policies or Firebase Auth with Firestore security rules. Those services protect the data they hold; adding their keys does not give htmlhost Collections per-user permissions.
  • Custom server code and incoming webhooks. A secure call makes a predefined outgoing request when a visitor triggers it. It cannot run your own server code or receive a payment provider's webhook. For those tasks, use a backend function such as Supabase Edge Functions, and have your htmlhost pages use the resulting API.

Templates and manual setup

If you want to configure a call yourself, select Use a template under Secure calls for Stripe or Mailchimp, or Create manually for the full form. You set the service address, key, request and returned fields. Other public HTTPS APIs must fit the supported request and authentication options. Each site can have up to 20 secure calls.

Limits that keep calls safe

  • A call only answers your own site's pages, on its htmlhost.co address and your custom domains.
  • Each visitor can make 20 calls a minute, and each site 300.
  • Calls go only to public web addresses. A shared project password gates calls like pages, but does not authenticate individual visitors. Saving an auth provider's key does not make calls verify visitor sessions.
  • Each call can be switched off in one click, and shows how often it ran and how the service last answered.

Anyone can trigger a call the way your page would, just as anyone can send a form. So set up calls that are fine for any visitor to make, like subscribing an email or starting a payment at your price.

With your own AI tools

Claude, Cursor, Codex and other tools you connect see the same list: htmlhost keys in the CLI, and pull and clone write it into your project's AGENTS.md. The htmlhost MCP server and the Claude connector include it too. Secret values are never sent to any of them.

They can save keys too. Paste a key into the chat and ask, for example “Save this as my Stripe test key: sk_test_…”, and the tool adds it to the site's Keys. It tells public from secret by the key's format and asks you only when it can't. In a terminal it's htmlhost keys set STRIPE_SECRET_KEY, which asks for the value without showing it. See the agent guide for the details.

For developers

A page sends the fields its call accepts to an address on the same site. Handle a failed response before showing success:

Call a saved subscribe action
const res = await fetch("/__hh/call/subscribe", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ email }),
});
const { ok, error } = await res.json();
if (!res.ok || !ok) throw new Error(error || "Couldn't subscribe. Try again.");

Related

Frequently asked questions

Do I need to configure a secure call myself?

No. Ask AI to build the feature using your saved key by name. AI Edit and connected tools can create the call after confirmation. If you prefer to add it in the dashboard, or your tool cannot create it, ask for a JSON definition and use Keys → Secure calls → Paste a definition → Review call → Add call.

If I change a key, do I need to update my website?

No. Pages refer to a public key by its name, and htmlhost fills in the current value whenever it serves the page, so a changed key reaches your live site within about a minute. Secret keys are used the moment a secure call runs. Saving a key never edits or republishes your pages.

How do I know if a key is public or secret?

Your service labels it. “Public” or “publishable” keys are meant to be seen; “secret”, “private” or plain “API” keys are not. When you're not sure, choose Secret. htmlhost also recognises common formats and warns you before saving a secret-looking value as Public.

Can I see a secret key after saving it?

No, only its last four characters, so you can tell which one is saved. You can replace it at any time. Keep your own copy in your service's dashboard or a password manager.

Who can manage keys?

The site's owner and Admins. Editors and Contributors, and the AI tools they use, see each key's name and the values of public keys only.

Can my AI tool add keys for me?

Yes. Give Claude, Cursor or another connected tool the key and ask it to save it to your site. It works out whether the key is public or secret from its value, and asks you only when it can't tell. Anything you paste into a chat stays in that chat's history, so test keys are a good fit; you can always paste live secret keys in the dashboard instead.

What if I remove a key a secure call uses?

htmlhost won't let you: it names the calls that use the key, so you can remove or change them first.

Can another website use my secure calls?

Not from its pages: a secure call refuses what a browser sends from another website. Someone can still send the same request your page sends, as they can with a form, within the same limits. That's why calls should only do what any visitor may do, with the price and everything else that matters fixed.

What happens if my Pro plan ends?

Your keys and calls are kept. Public keys already in your pages keep working; secure calls stop running until the site's owner is on Pro again.

Add your first key

Open your site in the dashboard, then Keys.

Go to your sites