Skip to main content

Event Stream

The event stream is the primary way for bots to receive notifications about challenges, games starting, and game endings.

GET /api/stream/event

Stream incoming events in real-time. This is a long-lived HTTP connection that sends newline-delimited JSON (ndjson).

Authentication

Requires OAuth token with bot:play, board:play, or challenge:read scope.

Request

Event Types

object
A game has started. Connect to the game stream immediately.
object
A game has finished.
object
Someone challenged you.
object
A challenge was declined.
object
A challenge was canceled.

Game Stream

GET /api/bot/game/stream/

Stream the state of a game being played with the Bot API. Provides real-time updates for moves, draw offers, takeback requests, and opponent presence.
Connect to this stream as soon as you receive a gameStart event.

Authentication

Requires OAuth token with bot:play scope.

Parameters

string
required
The game ID to stream

Request

Event Types

object
Full game data. This is always the first message sent. Contains both game metadata and current state.
object
Current state of the game. Sent after each move.
object
A chat message.
object
The opponent left the game.

Make a Move

POST /api/bot/game//move/

Make a move in a game being played with the Bot API.

Authentication

Requires OAuth token with bot:play scope.

Parameters

string
required
The game ID
string
required
The move in UCI format (e.g., e2e4, e7e5, e1g1 for castling)
boolean
Whether to offer a draw with this move

Request

Response

boolean
Whether the move was successful

UCI Move Format

Moves must be in Universal Chess Interface (UCI) format:
  • Normal moves: e2e4, g8f6
  • Castling: e1g1 (kingside), e1c1 (queenside)
  • Promotion: e7e8q (promote to queen), a7a8n (promote to knight)
  • En passant: Use the destination square (e.g., e5d6)

Additional Game Actions

Abort Game

POST /api/bot/game//abort Abort a game. Only possible in the first few moves.

Resign Game

POST /api/bot/game//resign Resign a game.

Write in Chat

POST /api/bot/game//chat Post a message in the game chat.
string
required
Chat room: player (private) or spectator (public)
string
required
Message text

Complete Bot Example


Best Practices

Connection Management

  1. Keep Streams Alive: The event and game streams are long-lived connections
  2. Handle Disconnections: Implement reconnection logic with exponential backoff
  3. Process Events Quickly: Don’t block the stream processing thread
  4. Use Threads: Handle each game in a separate thread

Performance

  1. Think Time: Respect time controls and don’t take too long to move
  2. Memory: Clean up finished games to avoid memory leaks
  3. Rate Limits: Avoid making too many API calls

Fair Play

  1. Engine Strength: Don’t make your bot play at unrealistic strength
  2. No Unfair Advantage: Follow Lichess Terms of Service
  3. Handle Draws: Respond appropriately to draw offers

See Also