Skip to main content

Chat API

Asynchronous chat between humans and LLM agents — poll, reply, history, unread count, file uploads.


Chat API

The Chat API enables asynchronous messaging between humans and LLM agents. Unlike synchronous chat (ChatGPT-style), the human can leave messages while the agent is working — the agent polls between tool calls.

How It Works

Human (browser) ──POST /chat/send──▶ Synapse ◀──GET /chat/poll── Agent (LLM)
                                     │
                                     └── marks messages as read on poll
  1. Human sends a message via the web UI (uses JWT)
  2. Message is stored, marked as unread
  3. Agent polls GET /chat/poll between tool calls
  4. Poll returns all unread messages and marks them as read
  5. Agent processes the message, optionally replies via POST /chat/reply

Endpoints

GET /chat/poll

Poll for new messages from the human. Returns unread messages and marks them as read. Use this between tool calls.

curl -H "Authorization: Bearer YOUR_MIND_KEY" \
     https://synapse.schaefer.zone/chat/poll

Response:

{
  "messages": [
    {
      "id": "msg_001",
      "role": "human",
      "content": "How's the deployment going?",
      "created_at": "2026-06-27T..."
    }
  ]
}

POST /chat/reply

Send a message as the agent.

curl -X POST https://synapse.schaefer.zone/chat/reply \
  -H "Authorization: Bearer YOUR_MIND_KEY" \
  -H "Content-Type: application/json" \
  -d '{"content": "Deployment is 80% done. CI is green, just waiting for Docker push."}'

POST /chat/send

Send a message as the human (requires JWT, not Mind Key).

curl -X POST https://synapse.schaefer.zone/chat/send \
  -H "Authorization: Bearer YOUR_JWT" \
  -H "Content-Type: application/json" \
  -d '{"content": "Can you check the logs?"}'

GET /chat/history

Get recent chat history (both roles). v1.23.3: full pagination — ALL historic messages are reachable, not just the newest window.

# Newest 50
curl -H "Authorization: Bearer YOUR_MIND_KEY" \
     "https://synapse.schaefer.zone/chat/history?limit=50"

# Exact single message by id (even very old, incl. quoted_* + files)
curl -H "Authorization: Bearer YOUR_MIND_KEY" \
     "https://synapse.schaefer.zone/chat/history?id=9606"

# id-window around a message (±25) — e.g. for #id references
curl -H "Authorization: Bearer YOUR_MIND_KEY" \
     "https://synapse.schaefer.zone/chat/history?around_id=9606"

# Older page: everything before id N (descending walk, has_more flag)
curl -H "Authorization: Bearer YOUR_MIND_KEY" \
     "https://synapse.schaefer.zone/chat/history?before_id=9000&limit=200"

# Ascending catch-up from id N (iterate gaplessly until count < limit)
# since_id and after_id are aliases of since
curl -H "Authorization: Bearer YOUR_MIND_KEY" \
     "https://synapse.schaefer.zone/chat/history?since=8800&limit=200"

# Classic pagination backwards from the newest end (offset + next_offset)
curl -H "Authorization: Bearer YOUR_MIND_KEY" \
     "https://synapse.schaefer.zone/chat/history?limit=200&offset=200"

Parameters: limit 1..500 (default 50) · id · around_id · before_id · since/since_id/after_id · offset · q (fulltext) · mine · mentions · from/to (epoch seconds). Responses include count, has_more and next_offset (NULL = end).

GET /chat/unread

Get unread message count.

# Count unread messages from human (for agent)
curl -H "Authorization: Bearer YOUR_MIND_KEY" \
     "https://synapse.schaefer.zone/chat/unread?role=agent"

# Count unread messages from agent (for human)
curl -H "Authorization: Bearer YOUR_JWT" \
     "https://synapse.schaefer.zone/chat/unread?role=human"

GET /chat/status

Get chat session status (last message timestamps, unread counts).

curl -H "Authorization: Bearer YOUR_MIND_KEY" \
     https://synapse.schaefer.zone/chat/status

POST /chat/upload

Upload a file attachment for a specific message (multipart form).

curl -X POST https://synapse.schaefer.zone/chat/upload \
  -H "Authorization: Bearer YOUR_JWT" \
  -F "message_id=msg_001" \
  -F "file=@screenshot.png"

GET /chat/files/:message_id

List file attachments for a message.

curl -H "Authorization: Bearer YOUR_JWT" \
     https://synapse.schaefer.zone/chat/files/msg_001

GET /chat/file/:file_id

Download a file attachment.

curl -H "Authorization: Bearer YOUR_JWT" \
     https://synapse.schaefer.zone/chat/file/file_001 --output download.png

Polling Pattern

Poll every 30-60 seconds between tool calls. Don't poll more frequently — it wastes API quota and provides no benefit.
# Pseudo-code
while working:
    messages = poll_chat()
    for msg in messages:
        process_message(msg)
        reply(f"Acknowledged: {msg.content}")
    do_one_tool_call()

Next Steps