Blog · 17 November 2026
Let your app's users bring their own Claude, OpenAI or Gemini key
You've added AI to your app. If everyone uses your key, you pay for everyone's usage, and one heavy user can run up your bill. The common answer is bring your own key (BYOK): each person adds their own key for Claude, OpenAI or Gemini, and pays for what they use.
It sounds simple. The hard part is keeping those keys safe, including from you. Here's what a good setup does, and how to build one from a chat.
What a safe setup looks like
A user's API key is as good as their credit card for that service. So:
- The page can save a key, but never read it back. After saving, people see "Saved · ends in x7Q2", with Replace and Remove. A key that can be read back can be stolen by anything running in the page.
- It's kept encrypted, with the encryption key held somewhere else. A copy of the database alone doesn't reveal anyone's key.
- Only that person's key is used for their requests, never someone else's, even by mistake.
- The app's code never handles the key. The request is sent with the key added on the way out. Code that never sees a key can't log it, show it or send it somewhere else.
- The owner can't read it. Not on the admin page, not in exports. You see that a key is set, and its last few characters.
Point 5 surprises people building their first BYOK app. But if you can read your users' keys, so can anyone who gets into your account, and your users have to trust you never will.
Why not just save it in the browser?
Keeping the key in the browser's storage and calling the AI service straight from the page is the quickest way to build this. It means the key sits in the page, where any script, browser extension or bug can read it. Some AI services also block calls made straight from browsers. More on keys in the frontend here.
Build it from a chat
With Toupas added to your chat, and an app that already has an AI assistant:
Let each person who uses my app add their own AI keys for Claude,
OpenAI and Gemini, and pick which one to use in each chat.
Add an "AI keys" panel with step-by-step help on getting a key from each
service, and a reminder to set a spending limit.
Toupas has a field type for exactly this, a secret. It does each of the five things above:
- The page can write it, never read it. Reading it gives only "set" and the last four characters.
- It's encrypted, with a key Toupas keeps for the app, outside the app's database.
- When the app calls Claude, OpenAI or Gemini, Toupas finds the key of the person who started the request and adds it itself. Claude, OpenAI and Gemini each take their key in a different place, and Toupas puts it in the right one.
- The admin page shows "set · ends in x7Q2", and Download everything leaves secrets out.
- If someone hasn't added a key yet, the page gets a plain message ("Add your own key first") and can open the keys panel.
When you approve the app's changes in the Toupas panel, it says plainly that keys people save for themselves never reach you.
What to tell your users
Put this in the keys panel, in your own words:
- Where to get a key: the API keys page of each service's developer console, with a direct link.
- Set a spending limit on the service before pasting a key. All three let you.
- Use a key just for this app, so you can revoke it without breaking anything else.
- Who can see it: nobody, including the app's owner. It's used only for your own requests.
Things to know
- Each person pays their own AI bill, directly to the service. Your hosting cost doesn't change.
- Keys are pasted, not signed in. Claude, OpenAI and Gemini don't offer a "sign in with your account" button for API access, so a key is the only way.
- One limitation: if you later move the app from the chat to your own code, your code runs with the app's encryption key, so it *could* read users' keys. That's more control, not more safety. Tell your users if you do.
Questions
What does BYOK mean for AI apps?
Bring your own key: each user adds their own API key for an AI service and pays for their own usage, instead of the app owner paying for everyone.
Is it safe to let users enter their OpenAI API key in my app?
It can be, if the key is stored encrypted on the server, can't be read back by the page or the owner, and is only used for that person's own requests.
Should I store user API keys in the browser?
No. Anything in the browser can be read by scripts in the page and by extensions. Keep them on the server, encrypted.
Can my app's users sign in with their Claude or OpenAI account instead of a key?
Not for API access today. These services issue API keys from their developer consoles, so users paste a key.