Skip to content

adamlyttleapps/OpenAI-Proxy-PHP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

OpenAI-Proxy-PHP

A simple PHP script designed to protect your OpenAI API key and ensure secure communication.

Overview

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.

Features

  • 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

Usage:

To use OpenAI-Proxy-PHP, follow these steps:

Copy openai_proxy.php onto your server and then follow the instructions withint the source code:

  1. Copy the Script: Copy openai_proxy.php to your server.
  2. 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 = "";

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

Contributions are welcome! Feel free to open an issue or submit a pull request on the GitHub repository.

MIT License

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.

About

Simple PHP script to protect your Open API key

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages