SHM Labs/Writing/Add AI safely
GUIDE · AI FEATURES · API KEYS

Add AI to your app without leaking your key.

An AI assistant inside your own app is one of the most useful things you can build: it knows your data, so its answers fit. It's also the easiest place to make an expensive mistake, because an AI API key is like a credit card number. Here's how Creator Lab's assistant handles keys, and the pattern we'd use again.

01 · WHOSE KEY?

Your key, or each person's own

  • One shared key (yours): simple for users, but you pay for everyone's usage, so you'll want limits per person.
  • Bring your own key: each person pastes their own Claude or Gemini key and pays the provider directly. Better for small apps with a few users.

Creator Lab uses bring-your-own-key. The keys panel explains how to get one for each provider, step by step, including setting a monthly spend limit.

02 · WHERE THE KEY LIVES

Never in the page

Anything in your app's page, its JavaScript or the browser's storage can be read by anyone who opens the developer tools. So the rule is simple: the key goes to the server once, and never comes back.

  • Store it as a secret. In Creator Lab, keys are saved encrypted in a field of type “secret”. Pages and the admin area only see whether a key is set and its last four characters. Nobody can read it back, not even an admin.
  • Call the AI from the server. A small server action builds the request, and the hosting adds the person's key to it. The page only says “ask the assistant about chat 12”.
  • Limit where it can go. The action is only allowed to send to the AI providers' addresses. Even a bug can't send the key somewhere else.

Good sign: when we changed the assistant's code, Toupas asked for an approval first, because the action can reach outside services. Small friction, worth it.

03 · LET IT PROPOSE, NOT ACT

The assistant suggests; you apply

Give the AI your data as context, but don't let it change anything directly. Creator Lab's assistant answers with a message and a list of proposed changes (add a phase, add notes, move a video), shown as a short checklist with Apply and Dismiss. Nothing changes until you tap Apply.

Creator Lab AI tab with a question about a roadmap item and the assistant's answer
Ask about any roadmap item; useful answers can be saved as notes with one tap.
PROMPT TO COPYAdd an AI assistant tab to my app. Each person brings their own [Claude / Gemini] API key. - Save keys as secrets: the page must never be able to read them back; show only "saved, ends in 1234". - Call the AI from the server, with the key added there, never from the browser. - The assistant can propose changes to my data, but nothing changes until I tap Apply. - Show clear errors for a wrong key, a wrong model name, or running out of credit.
CHECKLIST

Before you ship an AI feature

  • Keys stored as secrets, shown only as the last 4 characters
  • AI calls made on the server
  • Outgoing calls limited to the provider's address
  • A spend limit set with the provider
  • AI proposes; a person applies
  • Friendly errors for bad keys and empty credit

See it in Creator Lab

An AI assistant that knows your roadmap and pipeline, using your own key, stored as a secret.

Keep reading