This is a simple API server wrapper for ChatGPT. It supports multiple OpenAI accounts, setting proxies for each account, and load-balancing requests between accounts.
You can install the package using
npm i -g @waylaidwanderer/chatgpt-api
then run it using
chatgpt-api
(or xvfb-run chatgpt-api
for headless servers).
This takes an optional --settings=<path_to_settings.js>
parameter, or looks for settings.js
in the current directory if not set, with the following contents:
module.exports = {
accounts: [
{
email: '[email protected]',
password: 'password1',
// Any other options that `ChatGPTAPIBrowser` supports...
},
{
email: '[email protected]',
password: 'password2',
proxyServer: 'user:pass@ip:port',
},
{
email: '[email protected]',
password: 'password3',
proxyServer: 'ip:port',
nopechaKey: 'accountNopechaKey',
},
// Add more accounts as needed...
],
// The port the server will run on (optional, defaults to 3000)
port: 3000,
// Your NopeCHA API key.
// This will be applied to all accounts but can be overridden on a per-account basis.
nopechaKey: 'nopechaKey',
};
Alternatively, you can install the package locally and run it using node index.js
:
- Clone this repository
- Install dependencies with
npm install
- Rename
settings.example.js
tosettings.js
in the root directory and change the settings where required. - Start the server using
xvfb-run node index.js
(for headless servers) ornode index.js
To start a conversation with ChatGPT, send a POST request to the server's /conversation
endpoint with a JSON body in the following format:
{
"message": "Hello, how are you today?",
"conversationId": "your-conversation-id (optional)",
"parentMessageId": "your-parent-message-id (optional)"
}
The server will return a JSON object containing ChatGPT's response:
{
"response": "I'm doing well, thank you! How are you?",
"conversationId": "your-conversation-id",
"messageId": "your-message-id"
}
If the request is unsuccessful, the server will return a JSON object with an error message and a status code of 503.
If no sessions have finished initializing yet:
{
"error": "No sessions available."
}
If there was an error sending the message to ChatGPT:
{
"error": "There was an error communicating with ChatGPT."
}
If you'd like to contribute to this project, please create a pull request with a detailed description of your changes.
This API server is powered by @transitive-bullshit's chatgpt-api (chatgpt on npm).
This project is licensed under the MIT License.