Skip to main content
The Chat API enables you to send messages to AI assistants and receive responses through HTTP requests or WebSocket connections.

Send Message

Send a message to an AI assistant in a chat session.
string
required
The unique identifier of the session
string
required
The message text to send to the AI
array
Optional array of file paths to include as context
array
Optional array of image file paths to include

Response

string
Unique identifier for the sent message
string
Message status: sent, processing, or completed

Example Request

cURL

Example Response

Stream Messages (WebSocket)

For real-time chat interactions, use the WebSocket connection to stream messages and responses.

Connect to WebSocket

Send Message via WebSocket

Receive Streaming Response

As the AI generates a response, you’ll receive multiple events:

Message Started

Content Delta

Streaming chunks of the AI’s response:

Tool Use

When the AI uses a tool (e.g., editing a file):

Message Completed

Message Error

Get Message History

Retrieve all messages in a session.
string
required
The unique identifier of the session
number
Maximum number of messages to return (default: 100)
number
Number of messages to skip (for pagination)

Response

array
Array of message objects

Example Request

cURL

Stop Generation

Stop the AI from generating a response mid-stream.
string
required
The unique identifier of the session

Example Request

cURL

Approve Plan

When a session is in plan mode and has proposed changes, approve the plan to execute it.
string
required
The unique identifier of the session
string
required
Execution mode for approved plan: build or yolo

Example Request

cURL

Answer Question

When the AI asks a question (waiting state), provide an answer.
string
required
The unique identifier of the session
string
required
The answer to the AI’s question

Example Request

cURL

WebSocket Connection

The WebSocket connection provides bidirectional real-time communication.

Authentication

Include your token as a query parameter:

Dual Emission

Jean uses a dual emission pattern for WebSocket events:
  1. Global broadcast: All events are sent to all connected clients
  2. Targeted emission: Events related to a specific session are also sent to clients that have subscribed to that session
This allows you to:
  • Listen to all activity across Jean (for dashboard views)
  • Subscribe to specific sessions for focused updates

Subscribe to Session

Unsubscribe from Session

Error Responses

The Chat API returns standard HTTP error codes:

Example Error Response

Best Practices

For real-time chat interactions, use the WebSocket connection to receive streaming responses and immediate updates. HTTP requests are better suited for batch operations or simple queries.
WebSocket connections can drop. Implement reconnection logic with exponential backoff to maintain a stable connection.
Cache message history on the client side to reduce API calls and improve response times. Use the WebSocket events to keep the cache synchronized.
Show typing indicators when receiving content-delta events to provide feedback to users during streaming responses.

Next Steps

Sessions API

Manage chat sessions within worktrees

Remote Access Guide

Learn more about Jean’s HTTP server and WebSocket API