Documentation
API Reference

API: Threads

Flapjack REST API endpoints for creating conversation threads and streaming agent messages via SSE.

Create conversation threads and send messages to agents. Message responses are streamed via Server-Sent Events (SSE).

Create Thread

POST /api/threads

Create a new conversation thread for an agent.

Request body:

FieldTypeRequiredDescription
agentIdstringYesThe agent's UUID
titlestringNoThread title
kindstringNosingle (default) or multiplayer
resourceBindingsarrayNoAttach external resource context
activeProfilestringNoSet the initial tool profile
systemPromptOverlaystring | string[]NoText appended to the agent's system prompt for this thread. Arrays are joined with \n\n.
curl -X POST https://api.flapjack.dev/api/threads \
  -H "Authorization: Bearer fj_live_..." \
  -H "Content-Type: application/json" \
  -d '{"agentId": "abc-123"}'

Response 200:

{
  "id": "thread-456",
  "org_id": "org-789",
  "agent_id": "abc-123",
  "title": null,
  "created_at": "2026-03-28T12:00:00Z"
}
πŸ“‹ Copy as prompt

Create a Flapjack thread by POSTing to /api/threads with an agentId in the body. Save the returned thread ID.


Update Thread

PATCH /api/threads/{threadId}

Update a thread's configuration.

Request body:

FieldTypeRequiredDescription
activeProfilestring | nullNoSet or clear the active tool profile
titlestringNoUpdate thread title
systemPromptOverlaystring | string[] | nullNoUpdate or clear the thread-level system prompt overlay
curl -X PATCH https://api.flapjack.dev/api/threads/thread-456 \
  -H "Authorization: Bearer fj_live_..." \
  -H "Content-Type: application/json" \
  -d '{"activeProfile": "triage"}'

Response 200:

{
  "id": "thread-456",
  "org_id": "org-789",
  "agent_id": "abc-123",
  "title": null,
  "active_profile": "triage",
  "created_at": "2026-03-28T12:00:00Z"
}

Send Message (Streaming)

POST /api/threads/{threadId}/messages

Send a user message and receive the agent's response as an SSE stream.

Request body:

FieldTypeRequiredDescription
contentstringYesThe user's message text
toolsarrayNoCustom tool definitions for client-side execution
toolResultsarrayNoResults for a previous requires_action event
modelOverridestringNoOverride agent's default model for this message
senderNamestringNoDisplay name (multiplayer threads)
senderIdstringNoSender user ID (multiplayer threads)
toolProfilestringNoUse a specific tool profile for this message
systemPromptOverlaystring | string[]NoText appended to the system prompt for this message only. Does not persist.
curl -N -X POST https://api.flapjack.dev/api/threads/thread-456/messages \
  -H "Authorization: Bearer fj_live_..." \
  -H "Content-Type: application/json" \
  -d '{"content": "Hello, what can you help me with?"}'

Response 200 (SSE stream):

event: meta
data: {"startedAt":"2026-03-28T12:00:01Z"}

event: token
data: {"delta":"I"}

event: token
data: {"delta":" can"}

event: token
data: {"delta":" help"}

event: token
data: {"delta":" you with..."}

event: done
data: {"ok":true,"messageId":"msg-001","content":"I can help you with..."}

SSE Event Types

EventFieldsDescription
metastartedAtStream metadata
tokendeltaText chunk from the LLM
tool_calltool: { id, name, arguments }Agent calling a tool
tool_executingtool_nameTool execution started
tool_resulttool_name, tool_call_id, resultTool execution result
auth_challengetoolName, challenge: { provider, redirectUrl, description? }Tool requires user to complete an OAuth flow. See Auth Challenges.
requires_actiontoolCallsAgent requests client-side tool execution
profile_switch_proposaltarget, reasonAgent proposes switching tool profile
doneok, messageId?, content, usage?, stopped?Full final response. messageId is absent when stopped early. usage contains token counts. stopped is present when interrupted.
errorcode, detail?Error occurred

See Concepts: Streaming for detailed event documentation.

πŸ“‹ Copy as prompt

Send a message to a Flapjack thread using curl with the -N flag for streaming. POST to /api/threads/{threadId}/messages with a JSON body containing content.


Stop Response

POST /api/threads/{threadId}/stop

Stop an active streaming response.

curl -X POST https://api.flapjack.dev/api/threads/thread-456/stop \
  -H "Authorization: Bearer fj_live_..."

Response 200:

{ "ok": true }

Participants (Multiplayer)

Manage participants in multiplayer threads.

GET /api/threads/{threadId}/participants

Returns all participants in a multiplayer thread.


POST /api/threads/{threadId}/participants

Add a participant.

FieldTypeRequiredDescription
userIdstringYesUser ID to add
displayNamestringNoDisplay name
rolestringNoowner or member (default)

DELETE /api/threads/{threadId}/participants

Remove a participant. Body: { "userId": "..." }.


Conversation History

Flapjack automatically maintains the full conversation history for each thread. Each call to sendMessage includes all prior messages as context. You do not need to send history manually.

You can also retrieve conversation history via the API:


List Threads

GET /api/threads?agentId={agentId}

List conversation threads for an agent. For JWT auth, results are scoped to the current user's threads. For API key auth, all org threads are returned.

Query parameters:

ParameterTypeRequiredDescription
agentIdstringYesFilter threads by agent UUID
cursorstringNoISO 8601 timestamp for cursor pagination (fetch threads older than this)
limitnumberNoMax threads to return (default 50, max 100)
orgIdstringNoTarget org (multi-org only)
curl https://api.flapjack.dev/api/threads?agentId=abc-123 \
  -H "Authorization: Bearer fj_live_..."

Response 200:

{
  "threads": [
    {
      "id": "thread-456",
      "org_id": "org-789",
      "agent_id": "abc-123",
      "title": null,
      "kind": "single",
      "status": "active",
      "created_at": "2026-04-01T12:00:00Z",
      "updated_at": "2026-04-01T12:05:00Z"
    }
  ],
  "nextCursor": "2026-03-31T10:00:00Z"
}

When nextCursor is null, there are no more pages. Pass it as the cursor parameter to fetch the next page.

Copy as prompt

List my Flapjack threads for an agent using GET /api/threads?agentId={id}. The response includes a nextCursor for pagination.


Get Messages

GET /api/threads/{threadId}/messages

Retrieve the message history for a thread. Only user and assistant role messages are returned.

Query parameters:

ParameterTypeRequiredDescription
limitnumberNoMax messages to return (default 100, max 200)
offsetnumberNoNumber of messages to skip (default 0)
curl https://api.flapjack.dev/api/threads/thread-456/messages \
  -H "Authorization: Bearer fj_live_..."

Response 200:

{
  "messages": [
    {
      "id": "msg-001",
      "role": "user",
      "content": "Hello!",
      "sender_name": null,
      "created_at": "2026-04-01T12:00:01Z"
    },
    {
      "id": "msg-002",
      "role": "assistant",
      "content": "Hi! How can I help you today?",
      "sender_name": null,
      "created_at": "2026-04-01T12:00:03Z"
    }
  ],
  "total": 2
}
Copy as prompt

Fetch message history for a Flapjack thread using GET /api/threads/{threadId}/messages. Supports limit and offset for pagination.


Next Steps

Docs last updated May 11, 2026