The ChatGPT Proxy is a Node.js application that acts as a proxy for interacting with OpenAI's ChatGPT API. It provides a simple HTTP server that listens to incoming requests, validates the requests, and forwards them to the ChatGPT API, returning the responses to the clients.
Before using the ChatGPT Proxy, you need to have the following prerequisites set up:
-
Node.js: Make sure you have Node.js installed on your system. You can download it from nodejs.org.
-
OpenAI API Key: You must have an OpenAI API key to authenticate your requests to the ChatGPT API. You can obtain an API key from the OpenAI platform.
-
Environment Variables: Create a
.envfile in the project directory or configure environment variables in your deployment environment with the following variables:OPENAI_API_KEY: Your OpenAI API key.EXPECTED_STARTS: Comma-separated list of strings expected in the first message content to validate requests.OPENAI_MODEL(optional): Default model to use when the client request omitsmodel(default:gpt-5).HOST(optional): The hostname to bind to (default: "localhost").PORT(optional): The port to listen on (default: 3000).SSL_KEY_PATH(optional): Path to your SSL key file for HTTPS (required if running with SSL).SSL_PEM_PATH(optional): Path to your SSL PEM file for HTTPS (required if running with SSL).
-
Clone this repository to your local machine:
git clone https://github.com/your-username/chargpt-proxy.git -
Navigate to the project directory:
cd chargpt-proxy -
Install the required Node.js packages using npm:
npm install
-
Set up the required environment variables by creating a
.envfile in the project directory or configuring them in your deployment environment.OPENAI_API_KEY=your_openai_api_key EXPECTED_STARTS=desired_start_string_one,another_start OPENAI_MODEL=gpt-5 HOST=localhost PORT=3000 SSL_KEY_PATH=/path/to/your/keyfile.key (required for HTTPS) SSL_PEM_PATH=/path/to/your/pemfile.pem (required for HTTPS) -
Start the ChatGPT Proxy server:
npm start -
The server will now be running and listening for incoming requests. You can send POST requests to
http://localhost:3000/openai-completionwith a JSON payload containing your messages. If you omitmodel, the server will inject the default fromOPENAI_MODEL.Example POST request:
{ "messages": [ { "role": "user", "content": "Your expected start ... actual prompt" } ] }Or explicitly specify a model to override the default:
{ "model": "gpt-4o-mini", "messages": [ { "role": "user", "content": "Your expected start ... actual prompt" } ] } -
The proxy will validate that the first message
contentincludes one ofEXPECTED_STARTS, then forward the request to the OpenAI API, returning the response.
This project is licensed under the MIT License - see the LICENSE file for details.
- This project uses the OpenAI Node.js library for API communication.
- Special thanks to OpenAI for providing the ChatGPT API.
Feel free to customize and extend this README.md to provide more detailed information or additional usage instructions if necessary.
Please make sure to replace `"your-username"` with your actual GitHub username in the clone URL and update any other placeholders with your specific information as needed.