---
title: "Common API flows"
description: "Send between sessions and create, fork, rename, archive, and revive side-chat threads."
url: "https://www.thecompany.company/docs/api/common-flows"
---

# Common API flows

> Send between sessions and create, fork, rename, archive, and revive side-chat threads.

These examples continue the [quickstart](/docs/api/quickstart), using Bash, `curl`, `jq`, `API_BASE`, `TCC_ACCESS_TOKEN`, `ENVIRONMENT_ID`, and `SESSION_ID`. Keep the token's `sessions:read` and `sessions:write` scopes and access to the sessions involved.

## Send from one session to another [#send-from-one-session-to-another]

Unlike `TextSubmitted`, `POST /v1/sessions/{id}/messages` sends **from another session**. The target must be writable, and the sender must be readable by the caller and different from the target. The server stamps `session.message` provenance so the receiving agent can distinguish the sending session from its own user.

Create a sender, or use an existing readable session ID:

```bash
SENDER_SESSION_ID=$(jq -n --arg env "$ENVIRONMENT_ID" \
  '{environmentId: $env, name: "API sender"}' |
  curl --fail-with-body --silent --show-error \
    -H "Authorization: Bearer $TCC_ACCESS_TOKEN" \
    -H 'Content-Type: application/json' \
    --data-binary @- "$API_BASE/sessions" | jq -er '.id')

MESSAGE_KEY="handoff-$SENDER_SESSION_ID-1"
jq -n --arg sender "$SENDER_SESSION_ID" --arg key "$MESSAGE_KEY" \
  '{senderSessionId: $sender, messageId: $key,
    message: "Review the plan and reply with the main risk."}' |
  curl --fail-with-body --silent --show-error \
    -H "Authorization: Bearer $TCC_ACCESS_TOKEN" \
    -H 'Content-Type: application/json' \
    --data-binary @- "$API_BASE/sessions/$SESSION_ID/messages"
```

Success returns `204 No Content`, not a completed agent response. Follow the receiving session's [events](/docs/api/streaming). The optional `messageId` is an idempotency key (1–128 characters): authorized retries with the same key deduplicate; omitting it makes each request a new delivery.

## Create and address a side-chat thread [#create-and-address-a-side-chat-thread]

Threads stay inside the same session. Create a blank side chat, save the numeric `threadId`, then submit text to that thread. This does not create another session.

```bash
THREAD_KEY="side-chat-$SESSION_ID-1"
THREAD_ID=$(jq -n --arg key "$THREAD_KEY" \
  '{label: "Plan review", idempotencyKey: $key}' |
  curl --fail-with-body --silent --show-error \
    -H "Authorization: Bearer $TCC_ACCESS_TOKEN" \
    -H 'Content-Type: application/json' \
    --data-binary @- "$API_BASE/sessions/$SESSION_ID/threads" |
  jq -er '.threadId')

jq -n --argjson thread "$THREAD_ID" --arg key "$THREAD_KEY-prompt" \
  '{threadId: $thread, idempotencyKey: $key, receipt: true,
    events: [{_tag: "TextSubmitted",
      messages: [{content: "Give me an independent review of this plan."}]}]}' |
  curl --fail-with-body --silent --show-error \
    -H "Authorization: Bearer $TCC_ACCESS_TOKEN" \
    -H 'Content-Type: application/json' \
    --data-binary @- "$API_BASE/sessions/$SESSION_ID/events" | jq .

curl --fail-with-body --silent --show-error \
  -H "Authorization: Bearer $TCC_ACCESS_TOKEN" \
  "$API_BASE/sessions/$SESSION_ID/events?threadId=$THREAD_ID&limit=100" |
  jq '{data, firstId, lastId, hasMore}'
```

For writes, omitting `threadId` targets root thread `0`. For `GET /events`, omitting it includes all threads. SSE has no `threadId` query filter; filter the session stream's events by `threadId` in your client. List side chats, including archived ones, in creation order with:

```bash
curl --fail-with-body --silent --show-error \
  -H "Authorization: Bearer $TCC_ACCESS_TOKEN" \
  "$API_BASE/sessions/$SESSION_ID/threads" |
  jq '.data[] | {threadId, label, status, forkSource}'
```

The list excludes threads running other agents, such as subagents. Labels contain 1–255 characters.

## Fork the root conversation into a side chat [#fork-the-root-conversation-into-a-side-chat]

Choose a **root transcript message ID**: the numeric event `id` of the message's `message.created` or `message.started` event, not its client-generated string ID, a thread ID, or an arbitrary event cursor. A `message.started` cutoff must have settled with `message.completed`. A missing, unsettled, or non-replayable cutoff is rejected; do not blindly substitute `lastId` from an event page.

This read shows `message.created` candidates from the root thread. Choose one with replayable conversation content; page through earlier or later events if needed.

```bash
curl --fail-with-body --silent --show-error \
  -H "Authorization: Bearer $TCC_ACCESS_TOKEN" \
  "$API_BASE/sessions/$SESSION_ID/events?threadId=0&limit=100" |
  jq '.data[] | select(.payload.type == "message.created") | {id, payload}'
read -r -p 'Settled root transcript message ID: ' SOURCE_MESSAGE_ID

FORK_THREAD_ID=$(jq -n --argjson source "$SOURCE_MESSAGE_ID" \
  --arg key "fork-$SESSION_ID-$SOURCE_MESSAGE_ID-1" \
  '{sourceMessageId: $source, label: "Alternative approach", idempotencyKey: $key}' |
  curl --fail-with-body --silent --show-error \
    -H "Authorization: Bearer $TCC_ACCESS_TOKEN" \
    -H 'Content-Type: application/json' \
    --data-binary @- "$API_BASE/sessions/$SESSION_ID/threads/fork" |
  jq -er '.threadId')
```

This copies the root conversation through the selected message into a side chat, excluding tool results and reasoning. It does not fork the whole session or select an arbitrary source thread. To continue the fork, submit text with `threadId: $FORK_THREAD_ID` using the preceding event-push pattern.

Create and fork both accept optional `events` for kickoff. When supplied, inspect the returned `kickoff` field (`accepted`, `duplicate`, or `failed`) as well as `threadId`: a failed kickoff still leaves a created thread. Retry with the same creation key to reuse that thread and retry kickoff, or send only its events to the returned thread.

Creation keys are scoped to caller and session for 48 hours, shared across create and fork. Reusing a key returns the first thread; its first label, model, source, and kickoff events win. Use a fresh key for different work. Omitting the key allocates a new thread on each call. Creation and revival can fail when the active side-chat capacity is reached.

## Rename, archive, and revive a thread [#rename-archive-and-revive-a-thread]

These operations address a side-chat thread, never root thread `0`. Rename and archive return `204 No Content`; revive returns a `threadId`. Archiving a thread does not archive its session.

```bash
curl --fail-with-body --silent --show-error -X PATCH \
  -H "Authorization: Bearer $TCC_ACCESS_TOKEN" \
  -H 'Content-Type: application/json' \
  --data '{"label":"Reviewed plan"}' \
  "$API_BASE/sessions/$SESSION_ID/threads/$THREAD_ID"

curl --fail-with-body --silent --show-error -X POST \
  -H "Authorization: Bearer $TCC_ACCESS_TOKEN" \
  "$API_BASE/sessions/$SESSION_ID/threads/$THREAD_ID/archive"

curl --fail-with-body --silent --show-error -X POST \
  -H "Authorization: Bearer $TCC_ACCESS_TOKEN" \
  "$API_BASE/sessions/$SESSION_ID/threads/$THREAD_ID/revive" | jq '{threadId}'
```
