A simple PHP script designed to protect your OpenAI API key and ensure secure communication.
OpenAI-Proxy-PHP is a PHP script that secures your OpenAI API key, preventing it from being exposed in your application code or transmitted in plaintext over the network. This script is utilized in the AIWrapper-SwiftUI repository to enhance security.
- API Key Protection: Safeguard your OpenAI API key from exposure.
- Secure Communication: Prevents the API key from being transmitted in plaintext.
- Customizable Prompts: Easily configure custom prompts for your AI.
- Shared Secret Key: Optional shared secret key for an additional layer of security.
This script is used in the AIWrapper-SwiftUI repo located at https://github.com/adamlyttleapps/OpenAI-Wrapper-SwiftUI
To use OpenAI-Proxy-PHP, follow these steps:
Copy openai_proxy.php onto your server and then follow the instructions withint the source code:
- Copy the Script: Copy openai_proxy.php to your server.
- Configure the Script: Open the openai_proxy.php file and follow these instructions:
// STEP 1: ADD YOUR OPENAI KEY
$openai_key = "sk-XXXXXUcxGZXXXXXUQOXDXXXXXkFJQ2AEXXXXXXi29v71RJF";
// STEP 2: SPECIFY THE LOCATION WHERE THIS SCRIPT IS STORED
$script_location = "https://adamlyttleapps.com/demo/OpenAIProxy-PHP";
// STEP 3: CONFIGURE YOUR CUSTOM PROMPT
$custom_prompt = "You are a friendly chatbot called 'Test Identifier: AI Wrapper Test Agent' whose only purpose is to assist the user with identifying what they have taken a photo of, tips, and other information which may be helpful";
// STEP 4: SETUP THE SHARED SECRET KEY
// (this is the secret key in the client and server, leave blank if you want to bypass this check)
$shared_secret_key = "";
When the $shared_secret_key is set, the script verifies the @$_POST['hash'] value by comparing it against md5("{$_POST['messages']}{$POST['shared_secret_key']}"). Each client request must encode the hash with the shared secret key, allowing you to control access by changing the key.
Contributions are welcome! Feel free to open an issue or submit a pull request on the GitHub repository.
This project is licensed under the MIT License. See the LICENSE file for more details.
This README provides a clear overview of the project, detailed usage instructions, and additional sections like examples, contributions, and licensing, making it more comprehensive and user-friendly.