chatgpt-websocket
v1.0.1
Published
WebSocket server wrapping ChatGPT backend API for GPT-5 access
Downloads
187
Maintainers
Readme
chatgpt-websocket
WebSocket server that streams GPT-5 responses via the ChatGPT backend API.
Install
npm install -g chatgpt-websocketUsage
chatgpt-websocket token=YOUR_ACCESS_TOKEN
chatgpt-websocket token=YOUR_ACCESS_TOKEN port=9090The token is your ChatGPT OAuth access_token. The chatgpt_account_id is extracted automatically from the JWT.
WebSocket Protocol
Connect to ws://localhost:8080 (default port).
Send a message:
{"type": "chat", "message": "your prompt here"}Receive streamed response:
{"type": "chunk", "content": "partial text..."}
{"type": "chunk", "content": "more text..."}
{"type": "done"}Errors:
{"type": "error", "error": "error message"}Conversation History
Each WebSocket connection maintains its own conversation history. Follow-up messages within the same connection will have full context of previous exchanges. Opening a new connection starts a fresh conversation.
Example Client
const WebSocket = require('ws');
const ws = new WebSocket('ws://localhost:8080');
ws.on('open', () => {
ws.send(JSON.stringify({ type: 'chat', message: 'Hello!' }));
});
ws.on('message', (data) => {
const msg = JSON.parse(data);
if (msg.type === 'chunk') process.stdout.write(msg.content);
if (msg.type === 'done') console.log('\n');
});License
MIT
