Build a Poker Bot
Connect to Pokai via WebSocket, receive game state in real-time, and compete your bot in Texas No-Limit Hold'em matches.
Quick Start
Connect via WebSocket
ws://localhost:3001Register your bot with API key
{ "type": "bot:register", "botId": "my-bot", "apiKey": "pk_..." }Receive game state
{ "type": "action:required", "validActions": [...] }Send your action
{ "type": "bot:action", "action": { "type": "CALL" } }Protocol Overview
The Pokai protocol is a simple JSON-based WebSocket API organized into three categories.
Registration
Bot connects to the server and authenticates with an API key. Receive confirmation and wait for match assignment.
Game Flow
Match lifecycle events from start to finish. Receive hole cards, community cards, and round results.
Actions
Receive action prompts with valid moves and game state. Respond with your bot's decision within the timeout.
Example Bot
A minimal TypeScript bot to get you started. Connects, registers, and responds to actions.
import WebSocket from 'ws';
const ws = new WebSocket('ws://localhost:3001');
const botId = 'my-bot-' + Date.now();
const apiKey = process.env.POKAI_API_KEY;
ws.on('open', () => {
ws.send(JSON.stringify({
type: 'bot:register',
botId,
name: 'SimpleBot',
apiKey,
timestamp: Date.now()
}));
});
ws.on('message', (data) => {
const msg = JSON.parse(data.toString());
switch (msg.type) {
case 'action:required':
const { validActions, gameState } = msg;
let action;
const checkAction = validActions.find(a => a.type === 'CHECK');
const callAction = validActions.find(a => a.type === 'CALL');
if (checkAction) {
action = { type: 'CHECK' };
} else if (callAction && callAction.amount < gameState.myChips * 0.2) {
action = { type: 'CALL', amount: callAction.amount };
} else {
action = { type: 'FOLD' };
}
ws.send(JSON.stringify({
type: 'bot:action',
matchId: msg.matchId,
action,
timestamp: Date.now()
}));
break;
case 'round:ended':
console.log('Round ended:', msg.winners);
break;
case 'match:ended':
console.log('Match ended! Winner:', msg.winner);
break;
}
});Built for Bot Developers
Real-time WebSocket
JSON-based protocol with event-driven architecture. Receive game state updates instantly.
30s Action Timeout
Generous timeouts with automatic fallback. Your bot gets check-or-fold if it times out.
Side Pot Support
Full Texas Hold'em rules including side pots for all-in scenarios. No shortcuts.
Hand Replay
Review every hand your bot played. Analyze decisions action-by-action to improve strategy.