Xeeph/oai-proxy
0
1---2title: oai-reverse-proxy3emoji: ๐4colorFrom: green5colorTo: purple6sdk: docker7pinned: false8duplicated_from: idosal/oai-proxy9---10<!-- -->11# OAI Reverse Proxy Server12 13Simple reverse proxy server for the OpenAI API.14 15## What is this?16If you have an API key you want to share with a friend, you can use this to keep your key safe while still allowing them to generate text with the API.17 18## Why?19OpenAI keys have full account permissions. They can revoke themselves, generate new keys, modify spend quotas, etc. You absolutely should not share them.20 21If you still want to share access to your key, you can put it behind this proxy to ensure it can't be used to do anything but generate text. You can also set a separate key on the proxy to gatekeep access.22 23## How to use24 25### 1. Get an API key26- Go to [OpenAI](https://openai.com/) and sign up for an account.27 28### 2. Clone this Huggingface repository to your account29- Go to [Huggingface](https://huggingface.co/) and sign up for an account.30- Once logged in, click on the `+` button in the top right corner and select `Duplicate this Space`.31 3233 34### 3. Set your OpenAI API key as a secret35- Click the Settings button in the top right corner of your repository.36- Scroll down to the `Repository Secrets` section and click `New Secret`.37 3839 40- Enter `OPENAI_KEY` as the name and your OpenAI API key as the value.41 4243 44**Do not paste the key into `server.js`!** That file is public and anyone can see it. Leave it alone; it will load the key from the secret you just created.45 46### 4. Deploy the server47- Your server should automatically deploy when you add the secret, but if not you can select `Factory Reset` from that same Settings menu.48 49### 5. Share the link50- The Service Info section below should show the URL for your server. You can share this with anyone to safely give them access to your OpenAI API key.51- Your friend doesn't need any OpenAI API key of their own, they just need your link.52- However, if you want to protect access to the server, you can add another secret called `PROXY_KEY`. This key will need to be passed in the Authentication header of every request to the server, just like an OpenAI API key.53 54**Note:** The `keys` section in the serverinfo screen may not correctly identify keys as trial/paid/GPT-4 unless you use the more advanced configuration described in `.env.example`.55 