How to hide API keys in Xcode code Swift UI — The most efficient way.
An API key is a simplified encrypted key that facilitates the authentication of a user to a particular service. For instance, an Open AI API key will grant the user access to employ their Natural Language Processing (NLP) and Large language model (LLM) services. To implement these API functionalities, the developer would embed key in a request query using a consistent route that maintains the projects’ intended behavior. However, the fluidity and recurrence of this procedure poses an expensive threat to the developer. How?
Most API services are paid for.
The weight of this payment is dependent on the data storage and query frequency. To put things into perspective, the Open AI api costs 1 cent per call, and an application with 100,000 query calls per month would rack up a monthly bill of $1,000. Some malicious developers may attempt to bypass this cost by stealing exposed API Keys from other unsuspecting developers. With this, they would embed this stolen API key in their project which allows them to use the API services while accumulating expenses that would be charged to the original API owner.
And so, I’m writing this article to prevent YOU from falling prey to this scam.