English | 中文
chatgpt-api is a tool that converts the functionality of the ChatGPT website into a chat API protocol. With this tool, you can easily integrate ChatGPT into your own applications and chatbots. It supports gpt3.5, gpt-4 (requires a plus account), and there is a possibility of being banned, so users are advised to use it at their own risk.
The project is implemented based on revChatGPT and defaults to using the go-chatgpt-api proxy to bypass Cloudflare.
To install chatgpt-api, follow these steps:
-
Clone the repository to your local machine:
git clone [email protected]:Beckjiang/chatgpt-api.git
-
Navigate to the project directory:
cd chatgpt-api
-
Copy the sample configuration files
config/config.sample.ini
andconfig/account.sample.ini
:cp config/config.sample.ini config/config.ini cp config/account.sample.ini config/account.ini
-
In the
config/config.ini
file, fill in your custom API Key under[api_key]
. -
Configure your ChatGPT account email and token in the
config/account.ini
file. You can configure multiple accounts. (Access tokens can be obtained here: https://chat.openai.com/api/auth/session) Example:[chatgpt_1] [email protected] access_token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Ik1UaEVOVUpHTkVNMVFURTRNMEZCTWpkQ05UZzVNRFUxUlRVd1FVSkRNRU13UmtGRVFrRXpSZyJ9.eyJodHRwczovL2FwaS5vcGVuYWkuY29tL3Byb2ZpbGUiOnsiZW1haWwiOiIxaDFyYmNtYm9AeXVud2VpbG9naW5taDMuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWV9LCJodHRwczovL2FwaS5vcGVuYWkuY29tL2F1dGgiOnsidXNlcl9pZCI6InVzZXItZ2wyVmZJMUI3d3g5WlpITHVDZ0FBaldhIn0sImlzcyI6Imh0dHBzOxxxxxxxxxxxxxxxxxxx [chatgpt_2] [email protected] access_token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Ik1UaEVOVUpHTkVNMVFURTRNMEZCTWpkQ05UZzVNRFUxUlRVd1FVSkRNRU13UmtGRVFrRXpSZyJ9.eyJodHRwczovL2FwaS5vcGVuYWkuY29tL3Byb2ZpbGUiOnsiZW1haWwiOiIxaDFyYmNtYm9AeXVud2VpbG9naW5taDMuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWV9LCJodHRwczovL2FwaS5vcGVuYWkuY29tL2F1dGgiOnsidXNlcl9pZCI6InVzZXItZ2wyVmZJMUI3d3g5WlpITHVDZ0FBaldhIn0sImlzcyI6Imh0dHBzOxxxxxxxxxxxxxxxxxxx
-
Run the application by executing the
docker-compose up
command to
To use chatgpt-api, make a POST request to http://127.0.0.1:8082/v1/chat/completes with a JSON payload containing the message you want to send to OpenAI(https://platform.openai.com/docs/api-reference/chat). Here's an example request:
(you need to change the $CONFIG_API_KEY
to that configure in [api_key]
)
curl http://127.0.0.1:8082/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $CONFIG_API_KEY" \
-d '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "Hello!"}]
}'
the param stream: true
also supports.
If you'd like to contribute to chatgpt-api, please read our contributing guidelines before submitting a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
If you have any questions or comments about chatgpt-api, please feel free to contact the project maintainer at [email protected].