MV Can I encrypt my plugin, to protect my API key?

I am experimenting with AI in a plugin. Not AI to build the plugin, but AI being used by the plugin.

This can be used for AI opponents or AI generated dialogue, where the player can have an actual conversation with the NPC's. All lore friendly to your own game.

However, to integrate ChatGTP or Gemini into my plugin, I need an API key. I got an API key like that and it works flawlessly.

The problem is: I am not supposed to share this AIP key, because it might be abused.

This is not a problem for sharing the plugin... Each dev should use their own API key, problem solved. However, I do need to include the API key for players. And those devs need to include their API key for their players. And this should somehow be done in a way that the players (or people who download AI projects for other reasons, like to steal API keys) can not in any way see this API key.

The only thing I can think of, is to encrypt the plugin, but is that even possible? And if so, how do I do this?
use API through param, add it to game plugin database => encrypt
your game (cooktool deluxe => halve) => problem solved.

inside plugin => cooktool deluxe => encrypt => they can find ways
to gain access to plugins, but they are all encrypted and hard to
reverse engineer =)

either of the 2 ways is the best way as some site that encrypt it
break sometimes plugin functionality.
use API through param, add it to game plugin database => encrypt
your game (cooktool deluxe => halve) => problem solved.

inside plugin => cooktool deluxe => encrypt => they can find ways
to gain access to plugins, but they are all encrypted and hard to
reverse engineer =)

either of the 2 ways is the best way as some site that encrypt it
break sometimes plugin functionality.
Sounds complecated. Cooktool Deluxe is a tool I need to download to encrypt the whole game? Then I will look into that first.

I don't mind if people use the plugin, I'd share it if I can make it work. And I can encrypt the graphics and audio with the build-in tool. The only problem is that the API needs to be hidden.

I feel like to understand your method, I need to know what cooktool deluxe is, so I guess I am going to google it now. 😛 I just hope I don't have to wrestle trough tons of aliexpress and temu ads about kitchen knives, mixers and combi-ovens, which are all cook tools and on those websites everything is marked deluxe. 😛 Haha.

I'll let you know if I can figure it out. 😛

---

Edit: I looked up cooktool deluxe, and now understand it is a RPG maker tool. 😛 Thanks, I'll look into it! 🙂
CookTool Deluxe = paid (there is free version too).

if you want people to download for their game, you can do so seperately,
as there are ways to get into your game and see the stuff as well.

even if plugins are encrypted.

halva is the best way to project your API from stealing, but I haven't tried
that part yet.

any way of protecting the API somehow would be useful.
Well, I can spend the 10 bucks. If people would want to use my plugin (which I make for myself...), then they would have to find a way to encrypt it themselves.

I don't mind if others integrate AI using this plugin as well, but it won't be a plug-and-play thing. The commands that are given to the AI in the plugin(s) I have in mind, are specific for those games. I mean, a plugin to make a real AI opponent in my card game would be a lot different then one that makes dialogue more dynamic. And even 2 plugins that are both made to make dialogue more dynamic, would not be the same in each game. Unless I can somehow unify it... Either way, if anyone would use this, there is still a lot they need to do themselves. Encrypting included. 😛

Anyhow, a $10 solution is a great solutions. Specially since (if it all works as intended) I will most likely use it is many more future projects. Not encrypting my work has always been the reason I did not make all my games downloadable. It is just too easy to open up a downloaded game in RPG maker, and rip everything that isn't graphics or audio.

So, yeah, this seems like a great solution. Thanks.
its for encrypting games, so a plugin release = without API,
so your API is save, for demo, game usage, I use the default option.

and it works smooth on my end.

but if the free version is there, you can try it out =)
if you like it, up to you to take deluxe version of not, halva is seperate
package which works with it, but you need to read the tutorial.

good luck though on this AI plugin, as some made it, but new plugins
and usage is always welcome ^^
Some made plugins to have AI make dialogue dynamic? That is amazing. I got the idea from this youtuber that made skyrim mods where all the characters in skyrim were controlled by AI.



But I would also want to use it to control the AI for my card game and maybe as an AI in my tic-tac-toe game?
this one is for MZ [InworldIntergration] made by Trihan.
Triancontaine had also 1 based on GPT I think, and another one
uses it too.

building one isn't easy though, as it require a lot of time and testing.
a lot of knowledge how the AI exactly work to grab information,
send the API to get respond etc.

but I do you wish good luck on the plugin, you might get an idea
by looking at those, as for MV if you aim for it, works differently.

but the idea is nice, but the harder part it, how would quests if you add them
work correctly without misleading its path =)

it depends on the road you take, what the people ask, try, etc.
this one is for MZ [InworldIntergration] made by Trihan.
Triancontaine had also 1 based on GPT I think, and another one
uses it too.

building one isn't easy though, as it require a lot of time and testing.
a lot of knowledge how the AI exactly work to grab information,
send the API to get respond etc.

but I do you wish good luck on the plugin, you might get an idea
by looking at those, as for MV if you aim for it, works differently.

but the idea is nice, but the harder part it, how would quests if you add them
work correctly without misleading its path =)

it depends on the road you take, what the people ask, try, etc.

I know it isn't easy, but I already did it for HTML, so I know how to do it.

It's cool Trihan made one for ChatGPT already, but I really want to create my own thing. 😛 I might take a look at his, but not before I finished mine. (I mean, if his plugin teaches me how to do it, then it is extra hard to create it completely by my own design later.)

I must confess, I had a lot of help by Gemini, to set up the Gemini API. Gemini didn't do it for me, but it showed me how, checked my process, tested my process etc. By pasting the code into a Gemini canvas, Gemini can see exactly what I did, how I did what I did and why I did it the way I did it.

So, when I hit a bug during the testing (inside the canvas), Gemini knows instantly what goes wrong, why it goes wrong and what I could do to to resolve it. Their solutions do not always run the first time, they might break something else and hit a new error, but AI will pick up on this and either alters his previous solution to the old bug, or offers a solution to the new bug. Often it does both, so you can choose which solution works best for you.

Anyhow, what I try to say is, I know it is hard, but Gemini helped me understand how Gemini works, and how to use if effectively. (Although Gemini is often like a high school math teacher: Their solutions to a problem are often more complicated than they need to be. Once I understand the solution they offer, it is only a matter of time before I figure out a way to simplify it. But then again, simplify in my case means: "Better to understand, for me" and in turn that means: "Recreate it with code Iunderstand." Which could make the code longer instead of shorter, but at least this way I know I can maintain and debug the code myself.)

By the way, once you've set up the API and understand how to ask for a response from gemini, making a plugin with it isn't any harder than any other RPG maker plugin, since... Well, asking for a reply (against certain in-game input, like a string in a variable, or args in the plugin command) is the only thing that is different in the plugin by adding AI.

Even if you make a super complex system with it, you only set up the API once, and ask for a reply of Gemini (or the LLM of your choice) and the system is now rephrased by AI.

It seems really complicated, but you know so much more about javascript than I do, so I promise you, if you feel like playing with using AI in your code, you can 100% do it... within a day. I had my first draft up and running in only a few hours. It took me many more hours to tweak it so it was all to my liking, but that fact that I had it running in like 2 or 3 hours, means it is not as hard as you might expect. 😛

---

Just to make this clear: I don't make this to be downloaded by others. I make this to create a game for my own, or actual if I can make this happen, I have multiple idea's on how I can use this effectively. There are a few smaller systems I can improve with integrating AI:

- Farmboy: I already created a function to hire Wietse, your tutor, after you completed the tutorials. (But it isn't live yet, It will be included in the next update). Wietse will take care of your crops, as long as you pay him and as long as you provide the right sources (fertilizer, water, and bug repellant.) but the way it is set up, he will always favor the same plants. When AI is involved, I can make it so that Wietse would prioritize the plants you need most.

- Tic-Tac-Toe: It should be interesting to play this against an AI, I know I have to make 100% sure that the AI only gives me the ID of the move they want to make, and I make the actual move, so I can decline illegal moves. Gemini and ChatGPT are known cheaters.

- Chess: I would use it to make add a funny twist to my chess engine. Maybe I let AI comment on all your moves like an annoying spectator. (I know better than using any LLM as a chess engine. They just do it.)

- Card Games: Now, here is an interesting one... My card games already have AI, and those games are a couple years old... How did I do that? I evented every single condition by hand!! And then I tested it and tweaked it. I did this by giving every single possible move the AI could do a score, and the move with the highest score would be the move played. How awesome would it be if I could have AI set those scores for me? That would be amazing. 😀

- Text Based Adventures: You, I don't think I have to explain how this can be epic when integrated with AI.

---

But I also have idea's for complete new systems I can make when I have AI to power me. How about games that are based on real life actualities, like the stock market. You can actually make an accurate traders game, with real-life stock values, because Gemini knows everything google knows. Or how about a modern game, where the NPC's talk about real news items. You're game would be relevant until the end of the AI era. 😛 Or a basket ball fan-game, where you have to predict the matches to come?

, I shouldn't share all those ideas. Some of them are really good, and easily doable with AI.

Sorry for the late reply...
Since you're already interacting with the web, one method might be to have your own API essentially. A PHP or other server-side script on a server you host that acts as an interface called by your client. All the requester gets access to is the result; the server-side script handles communication with the upstream source, doing all of the conversating and just rendering a simplified response.
The simple thing would be having a separate script keyed to your specific game, so a fantasy game with dialogue about your world will ALWAYS return that dialogue; useless to pretty much anyone who isn't playing your game. Then ditto for the card game logic, etc.
Otherwise, there's plenty of ways with various authorizations to permit and allow various traffic and deny others too.
Since you're already interacting with the web, one method might be to have your own API essentially. A PHP or other server-side script on a server you host that acts as an interface called by your client. All the requester gets access to is the result; the server-side script handles communication with the upstream source, doing all of the conversating and just rendering a simplified response.
The simple thing would be having a separate script keyed to your specific game, so a fantasy game with dialogue about your world will ALWAYS return that dialogue; useless to pretty much anyone who isn't playing your game. Then ditto for the card game logic, etc.
Otherwise, there's plenty of ways with various authorizations to permit and allow various traffic and deny others too.

Haha, you say it as if it is something you'd just do like that. I didn't understand half of it, and the other half seemed very complicated. 😛 I feel like such a noob now.

Maybe I should go back to school 😛

Thanks man, but I think I go for the encrypting solution first, if that works. You solution might even be better, but the encrypting solution is something I understand.
That's alright 🙂
I guess less technical response is: you're already sending information TO a page (the LLM), and getting information back FROM a page (also the LLM), so rather than have the game client communicating directly with the LLM and have it all open to everyone, have a page you control that's doing all the same stuff you're doing now in JS, but on your own webserver, acting as an intermediary to accept the input from your client games, be the one to hand it off to the LLM, and accept the response from the LLM and turn a simple response back to the client games. IE if you're handing things back and forth with someone, its you & them. If you really don't trust them or want to deal with them, you have your buddy Bob take the stuff instead and give it to you, and you give Bob stuff to give back to them. Bob is safe; Bob knows how to reach you, and Bob can deal with everyone, and not everyone is able to reach you, just Bob.
It'd be a bit of a fork; something like this works best in a language like PHP or Python, who run on the webserver and no one ever gets to see the code, just the output. All of the logic is ultimately the same and can be ported to a new language by some familiar with both sides. Be worth contemplating recruiting someone or hiring someone on Fiver to build a kind of "portal" for you~
I might know more JS, but no expert, specially not JS knowledgable for AI
generated content 😀 so there is a big difference as well =)

but I am curious where this brings though (even if I have no use for it).
it might be fun to play around with it.
That's alright 🙂
I guess less technical response is: you're already sending information TO a page (the LLM), and getting information back FROM a page (also the LLM), so rather than have the game client communicating directly with the LLM and have it all open to everyone, have a page you control that's doing all the same stuff you're doing now in JS, but on your own webserver, acting as an intermediary to accept the input from your client games, be the one to hand it off to the LLM, and accept the response from the LLM and turn a simple response back to the client games. IE if you're handing things back and forth with someone, its you & them. If you really don't trust them or want to deal with them, you have your buddy Bob take the stuff instead and give it to you, and you give Bob stuff to give back to them. Bob is safe; Bob knows how to reach you, and Bob can deal with everyone, and not everyone is able to reach you, just Bob.
It'd be a bit of a fork; something like this works best in a language like PHP or Python, who run on the webserver and no one ever gets to see the code, just the output. All of the logic is ultimately the same and can be ported to a new language by some familiar with both sides. Be worth contemplating recruiting someone or hiring someone on Fiver to build a kind of "portal" for you~
Like with JSON? Yeah, someone told me something like that before, but I don't have my own server and have no idea how to obtain and maintain one. Specially not for free. I refuse to pay a monthly subscription for projects that won't make any money. But even with a subscription, it is still a lot to learn before I can work with that.

I don't know anything about python either. I know some javascript and some HTML, but that's it.

Even though a webserver is probably the best solution, for me it would probably be best to encrypt instead. Just because then I can just pay for the plugin once and I'm ready to go.

A webserver is something for me to look into in the future, when I have completed games that I can monetize.

I might know more JS, but no expert, specially not JS knowledgable for AI
generated content 😀 so there is a big difference as well =)

but I am curious where this brings though (even if I have no use for it).
it might be fun to play around with it.
Okay, just to be clear, I do not use AI generated content. I create the content, but I use the AI as a tool inside the content.

Like I said, it is a small hand full of script calls you'd need to know to integrate AI in your project. Especially if it is only used to make conversations more generic.
Like with JSON? Yeah, someone told me something like that before, but I don't have my own server and have no idea how to obtain and maintain one. Specially not for free. I refuse to pay a monthly subscription for projects that won't make any money. But even with a subscription, it is still a lot to learn before I can work with that.
Yea, the final output you'd be harvesting would be a JSON reply, nice and easy to work with in RPGM.
Ultimately, webhosting these days is pretty cheap and for the basics very much like signing up for most services we use regularly. Neighborhood of $3-5/month for a lot of use cases that would more than do something like this, and be useful for other purposes. If you're going to promote games you develop as it is, its good to have a homebase; I see you do, and the server can host that same site/information so its not JUST hanging out in cyberspace for the one project.
I follow the desire/intent to go with what works, but just saying; be open to the idea, its not as hard or expensive as it might sound, and it's a lot more secure and opens other possibilities~
You mean my website? I don't have any control over that server space. The website is actually created using a blogger weblog. I choose this years ago, because it was the easiest way to update about my projects. Back then those projects were not games yet.

I don't mind the easy access of blogger, but I do not have any control over what I put on the server space. In fact, putting anything on there that isn't there to support the weblog, is in violation with their terms.
I highly advise encrypting an API key if it is paid or there is a free limit. I heard this horror story about a guy who left his Amazon AWS API key in his GitHub repository. In less than a month, his bill skyrocketed because all these people were sharing his key around and Amazon support wasn't helping him get out of the bill. If I remember right, his bill ended up being over $10k. I would imagine if someone used an OpenAI chat key, it could have a similar effect if enough users signed on. There should be a way to set a cap or limit on the account/server. That's what I did in Azure for storage.
Have you thought about using a local model? It's certainly won't be as good as OpenAI, but it could be enough for simple dialogue.

Although this solution would require a few gigs of ram, which is quite steep for an rpg maker game.

Original thread: https://forums.rpgmakerweb.com/threads/can-i-encrypt-my-plugin-to-protect-my-api-key.179064/