- Secure your API Key in FE clients by using Proxy Server with Authentication.
- OpenAI Proxy Server example using Firebase Cloud Functions with iOS ChatGPT App.
- 
Install firebase cli and firebase emulator. 
- 
Navigate to openai-proxy folder. 
- 
type firebase init.
- 
initialize your firebase project, you only need to enable functionsandemulator.
- 
Use Typescript (nodejs) as the language. 
- 
Create .env file in functions folder. It should contains CHAT_URL=https://api.openai.com/v1/chat/completions. If you don't want to use Google Secret Manager, you can also put your API key in here.
- 
To start localhost emulator. Navigate to functions folder, and type npm run serve
- 
To deploy, navigate to openai-proxyfolder and typefirebase deploy --only functions.
- By default, it uses Google Secret Manager to store the API Key. This requires billing
- If you don't want to use this, you can put the API_KEY in .env file. Update the source code to retrieve it from process.env.API_KEYand remove all code that uses defineSecret to retrive API key from Google Secret Manager.
- Provide your own bundle id in Signing & Capabilities tab (Xcode)
- Create iOS App in Firebase Dashboard project (make sure its the same project as the one you use to create the proxy server functions) using your bundleID.
- Download GoogleServices-Info.plist to your xcode project.
- Enable Authentication with Email provider in Firebase dashboard.
- Provide your own proxy server URL in ChatGPTAPI.swift
Check the full video tutorial at YouTube