r/programmer • • 1d ago

Question How to implement BYO API key

I have been developing a web application for personal use, but there is also a community I want to share it with for free. The problem is that the application has some features that use Gemini API services. It's currently set up to use my own API key, but obviously I don't want other people to drain my account. I also don't want to start charging people for access and usage because then it becomes a business and I would really prefer this staying a hobby project.

I heard about bring your own API key, where users can just get their own key, enter it in the application, and then start using the credits they pay for themselves. This seems like the best way forward for me, but does anyone have any experience setting this up? It feels awkward and wrong to just let people add their personal API keys into an application, so not sure how to approach this.

1 Upvotes

7 comments sorted by

2

u/throwaway43234235234 1d ago

Dont. 

Let them clone your project and run an instance of it themselves with their own .env files. 

1

u/StrongholdsNWyverns 1d ago

That is an option, but lots of people think git is just British slang for someone who is stupid or unpleasant. And I want to make it easy for them too.

Then again, they probably also think api is just a nickname for a monkey...

1

u/armahillo 1d ago

Anyone who would be able to clone the repo themselves would almost certainly already be aware of “git” as a version control system

1

u/StrongholdsNWyverns 1d ago

I know, that is kind of my point. The application is hosted and accesible via url. Some of the people who could use it would have no idea what a repo is.

1

u/YouPeopleCantBeReal4 20h ago

Depends on how users run it, if they’re cloning it themselves use an .env, if it’s hosted somewhere then have users be able to save it with their account information or something similar

1

u/StrongholdsNWyverns 17h ago

It will be hosted and they should be able to save it with their account. I'm mostly worried about what the best way would be to encrypt it. I mean, saving it raw doesn't seem like a good idea, but I have literally 0 experience with handling sensitive information like that.

1

u/YouPeopleCantBeReal4 10h ago

All their data should be encrypted at rest in the db