---
title: "Fork thread"
url: "https://www.thecompany.company/docs/api/sessions/fork-thread"
---

# Fork thread

- **Surface:** The App API
- **Endpoint:** `POST https://api.thecompany.company/v1/sessions/{id}/threads/fork`
- **Operation ID:** `sessions.forkThread`
- **Authentication:** `Authorization: Bearer <TOKEN>`

## Parameters

| Name | Location | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | `path` | `string` | Yes |  |

## Request Body (`application/json`)

**Required:** Yes

Schema: `ThreadForkInput`

| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `events` | `array<TextSubmitted \| Stopped \| SessionSuggestionResolved \| ...>` | No |  |
| `events[] (TextSubmitted)._tag` | `string` | Yes |  |
| `events[] (TextSubmitted).operationId` | `string` | No |  |
| `events[] (TextSubmitted).messages` | `array<TextInput>` | Yes |  |
| `events[] (TextSubmitted).messages[].content` | `string` | Yes |  |
| `events[] (Stopped)._tag` | `string` | Yes |  |
| `events[] (Stopped).operationId` | `string` | No |  |
| `events[] (SessionSuggestionResolved)._tag` | `string` | Yes |  |
| `events[] (SessionSuggestionResolved).suggestionId` | `string` | Yes |  |
| `events[] (SessionSuggestionResolved).outcome` | `string` | Yes |  |
| `events[] (SessionSuggestionResolved).sessionId` | `string \| null` | No | TypeID with prefix "asess_" (format-validated). |
| `events[] (SessionSuggestionResolved).claimId` | `string` | No |  |
| `events[] (SessionSuggestionResolved).operationId` | `string` | No |  |
| `events[] (SessionSuggestionClaimRequested)._tag` | `string` | Yes |  |
| `events[] (SessionSuggestionClaimRequested).suggestionId` | `string` | Yes |  |
| `events[] (SessionSuggestionClaimRequested).claimId` | `string` | Yes |  |
| `events[] (SessionSuggestionClaimRequested).placement` | `string` | Yes |  |
| `events[] (SessionSuggestionClaimRequested).sessionId` | `string` | Yes | TypeID with prefix "asess_" (format-validated). |
| `events[] (SessionSuggestionClaimRequested).operationId` | `string` | No |  |
| `events[] (SessionSuggestionClaimReleased)._tag` | `string` | Yes |  |
| `events[] (SessionSuggestionClaimReleased).suggestionId` | `string` | Yes |  |
| `events[] (SessionSuggestionClaimReleased).claimId` | `string` | Yes |  |
| `events[] (SessionSuggestionClaimReleased).error` | `string` | No |  |
| `events[] (SessionSuggestionClaimReleased).operationId` | `string` | No |  |
| `events[] (Resumed)._tag` | `string` | Yes |  |
| `events[] (Resumed).operationId` | `string` | No |  |
| `events[] (Cancelled)._tag` | `string` | Yes |  |
| `events[] (Cancelled).operationId` | `string` | No |  |
| `events[] (Cancelled).queueEntryId` | `number` | Yes |  |
| `events[] (QueueCancelled)._tag` | `string` | Yes |  |
| `events[] (QueueCancelled).operationId` | `string` | No |  |
| `events[] (Steered)._tag` | `string` | Yes |  |
| `events[] (Steered).operationId` | `string` | No |  |
| `events[] (Steered).queueEntryId` | `number` | Yes |  |
| `events[] (QueueFolded)._tag` | `string` | Yes |  |
| `events[] (QueueFolded).operationId` | `string` | No |  |
| `events[] (QueueFolded).queueEntryId` | `number` | Yes |  |
| `events[] (Rewound)._tag` | `string` | Yes |  |
| `events[] (Rewound).operationId` | `string` | No |  |
| `events[] (Rewound).messageId` | `number` | Yes |  |
| `events[] (Rewound).restoreWorkspace` | `boolean` | No |  |
| `events[] (BranchSwitched)._tag` | `string` | Yes |  |
| `events[] (BranchSwitched).operationId` | `string` | No |  |
| `events[] (BranchSwitched).branchId` | `number` | Yes |  |
| `events[] (Regenerated)._tag` | `string` | Yes |  |
| `events[] (Regenerated).operationId` | `string` | No |  |
| `events[] (Regenerated).messageId` | `number` | Yes |  |
| `events[] (Retried)._tag` | `string` | Yes |  |
| `events[] (Retried).operationId` | `string` | No |  |
| `events[] (Edited)._tag` | `string` | Yes |  |
| `events[] (Edited).operationId` | `string` | No |  |
| `events[] (Edited).messageId` | `number` | Yes |  |
| `events[] (Edited).parts` | `array<any>` | Yes |  |
| `events[] (QueueEdited)._tag` | `string` | Yes |  |
| `events[] (QueueEdited).operationId` | `string` | No |  |
| `events[] (QueueEdited).queueEntryId` | `number` | Yes |  |
| `events[] (QueueEdited).message` | `any` | Yes |  |
| `events[] (QueueEdited).releaseHold` | `boolean` | No |  |
| `events[] (QueueHeld)._tag` | `string` | Yes |  |
| `events[] (QueueHeld).operationId` | `string` | No |  |
| `events[] (QueueHeld).index` | `integer` | Yes |  |
| `events[] (QueueHeld).strategy` | `string \| null` | No |  |
| `events[] (QueueReleased)._tag` | `string` | Yes |  |
| `events[] (QueueReleased).operationId` | `string` | No |  |
| `events[] (QueueReleased).index` | `integer` | Yes |  |
| `events[] (QueueEntryHeld)._tag` | `string` | Yes |  |
| `events[] (QueueEntryHeld).operationId` | `string` | No |  |
| `events[] (QueueEntryHeld).queueEntryId` | `number` | Yes |  |
| `events[] (QueueEntryHeld).strategy` | `string \| null` | No |  |
| `events[] (QueueEntryHeld).reason` | `string \| null` | No |  |
| `events[] (QueueEntryReleased)._tag` | `string` | Yes |  |
| `events[] (QueueEntryReleased).operationId` | `string` | No |  |
| `events[] (QueueEntryReleased).queueEntryId` | `number` | Yes |  |
| `events[] (QueueEntryReleased).wake` | `boolean` | No |  |
| `events[] (QueueMoved)._tag` | `string` | Yes |  |
| `events[] (QueueMoved).operationId` | `string` | No |  |
| `events[] (QueueMoved).queueEntryId` | `number` | Yes |  |
| `events[] (QueueMoved).to` | `integer` | Yes |  |
| `events[] (ToolResultSubmitted)._tag` | `string` | Yes |  |
| `events[] (ToolResultSubmitted).operationId` | `string` | No |  |
| `events[] (ToolResultSubmitted).results` | `array<object>` | Yes |  |
| `events[] (ToolResultSubmitted).results[] (object).toolCallId` | `string` | Yes |  |
| `events[] (ToolResultSubmitted).results[] (object).state` | `string` | Yes |  |
| `events[] (ToolResultSubmitted).results[] (object).errorText` | `string` | Yes |  |
| `events[] (ToolResultSubmitted).results[] (object).toolCallId` | `string` | Yes |  |
| `events[] (ToolResultSubmitted).results[] (object).state` | `string` | Yes |  |
| `events[] (ToolResultSubmitted).results[] (object).output` | `any` | Yes |  |
| `events[] (SecretAskOutcomeSubmitted)._tag` | `string` | Yes |  |
| `events[] (SecretAskOutcomeSubmitted).operationId` | `string` | No |  |
| `events[] (SecretAskOutcomeSubmitted).toolCallId` | `string` | Yes |  |
| `events[] (SecretAskOutcomeSubmitted).mode` | `string` | Yes |  |
| `events[] (SecretAskOutcomeSubmitted).name` | `string` | No |  |
| `events[] (SecretAskOutcomeSubmitted).persisted` | `boolean` | Yes |  |
| `events[] (SecretAskOutcomeSubmitted).status` | `string` | Yes |  |
| `events[] (QuestionAnswerSubmitted)._tag` | `string` | Yes |  |
| `events[] (QuestionAnswerSubmitted).operationId` | `string` | No |  |
| `events[] (QuestionAnswerSubmitted).toolCallId` | `string` | Yes |  |
| `events[] (QuestionAnswerSubmitted).status` | `string` | Yes |  |
| `events[] (QuestionAnswerSubmitted).answers` | `array<object>` | Yes |  |
| `events[] (QuestionAnswerSubmitted).answers[].question` | `string` | Yes |  |
| `events[] (QuestionAnswerSubmitted).answers[].answer` | `string \| array<string>` | Yes |  |
| `events[] (DetachedInteractionSubmitted)._tag` | `string` | Yes |  |
| `events[] (DetachedInteractionSubmitted).operationId` | `string` | No |  |
| `events[] (DetachedInteractionSubmitted).toolCallId` | `string` | Yes |  |
| `events[] (DetachedInteractionSubmitted).toolName` | `string` | Yes |  |
| `events[] (DetachedInteractionSubmitted).resolution` | `any` | Yes |  |
| `events[] (ToolApprovalResponded)._tag` | `string` | Yes |  |
| `events[] (ToolApprovalResponded).operationId` | `string` | No |  |
| `events[] (ToolApprovalResponded).responses` | `array<object>` | Yes |  |
| `events[] (ToolApprovalResponded).responses[].approvalId` | `string` | Yes |  |
| `events[] (ToolApprovalResponded).responses[].toolCallId` | `string` | Yes |  |
| `events[] (ToolApprovalResponded).responses[].approved` | `boolean` | Yes |  |
| `events[] (ToolApprovalResponded).responses[].reason` | `string` | No |  |
| `events[] (MessagesSubmitted)._tag` | `string` | Yes |  |
| `events[] (MessagesSubmitted).operationId` | `string` | No |  |
| `events[] (MessagesSubmitted).messages` | `array<any>` | Yes |  |
| `events[] (MessagesSubmitted).behavior` | `string \| null` | No |  |
| `events[] (MessagesSubmitted).queue` | `object` | No |  |
| `events[] (MessagesSubmitted).queue.index` | `integer` | No |  |
| `events[] (MessagesSubmitted).queue.hold` | `boolean` | No |  |
| `events[] (MessageReactionSet)._tag` | `string` | Yes |  |
| `events[] (MessageReactionSet).operationId` | `string` | No |  |
| `events[] (MessageReactionSet).messageId` | `string` | Yes |  |
| `events[] (MessageReactionSet).emoji` | `string` | Yes |  |
| `events[] (MessageReactionSet).active` | `boolean` | Yes |  |
| `events[] (ModelConfigChanged)._tag` | `string` | Yes |  |
| `events[] (ModelConfigChanged).operationId` | `string` | No |  |
| `events[] (ModelConfigChanged).config` | `object` | Yes |  |
| `events[] (ModelConfigChanged).config.modelId` | `string` | Yes |  |
| `events[] (ModelConfigChanged).config.reasoning` | `string` | Yes |  |
| `events[] (ModelConfigChanged).config.speed` | `string \| null` | No |  |
| `events[] (SubscriptionPin)._tag` | `string` | Yes |  |
| `events[] (SubscriptionPin).operationId` | `string` | No |  |
| `events[] (SubscriptionPin).provider` | `string` | Yes |  |
| `events[] (SubscriptionPin).connectionId` | `string` | Yes |  |
| `events[] (ModeChanged)._tag` | `string` | Yes |  |
| `events[] (ModeChanged).operationId` | `string` | No |  |
| `events[] (ModeChanged).mode` | `string \| null` | Yes |  |
| `events[] (ModeChanged).ifUnset` | `boolean` | No | Apply only while the session has no active and no displaced mode. Reconciliation pushes (e.g. guide posture healing) use it so a re-assertion can never clobber a live mode such as plan. |
| `events[] (AllowedModesChanged)._tag` | `string` | Yes |  |
| `events[] (AllowedModesChanged).operationId` | `string` | No |  |
| `events[] (AllowedModesChanged).modes` | `array<string> \| null` | Yes |  |
| `events[] (CompactionRequested)._tag` | `string` | Yes |  |
| `events[] (CompactionRequested).operationId` | `string` | No |  |
| `events[] (CompactionRequested).instructions` | `string` | No |  |
| `events[] (CompactionRequested).attemptId` | `string \| null` | No |  |
| `events[] (GoalSubmitted)._tag` | `string` | Yes |  |
| `events[] (GoalSubmitted).operationId` | `string` | No |  |
| `events[] (GoalSubmitted).message` | `any` | Yes |  |
| `events[] (GoalSubmitted).tokenBudget` | `integer \| null` | Yes |  |
| `events[] (GoalSubmitted).behavior` | `string \| null` | No |  |
| `events[] (GoalEdited)._tag` | `string` | Yes |  |
| `events[] (GoalEdited).operationId` | `string` | No |  |
| `events[] (GoalEdited).objective` | `string \| null` | No |  |
| `events[] (GoalEdited).budget` | `object` | No |  |
| `events[] (GoalEdited).budget.tokenBudget` | `integer \| null` | Yes |  |
| `events[] (GoalEdited).revision` | `integer` | Yes |  |
| `events[] (GoalPauseRequested)._tag` | `string` | Yes |  |
| `events[] (GoalPauseRequested).operationId` | `string` | No |  |
| `events[] (GoalResumeRequested)._tag` | `string` | Yes |  |
| `events[] (GoalResumeRequested).operationId` | `string` | No |  |
| `events[] (GoalCleared)._tag` | `string` | Yes |  |
| `events[] (GoalCleared).operationId` | `string` | No |  |
| `idempotencyKey` | `string \| null` | No | Optional creation idempotency key, scoped to the caller and session for 48 hours. Retrying create or fork with the same key returns the first thread without consuming capacity, even without events. The first label, model, fork source, and kickoff events win. Omit for a new thread on every call. |
| `sourceMessageId` | `integer` | Yes |  |
| `label` | `string` | No |  |
| `modelConfig` | `object` | No |  |
| `modelConfig.modelId` | `string` | Yes |  |
| `modelConfig.reasoning` | `string` | Yes |  |
| `modelConfig.speed` | `string \| null` | No |  |
| `deliveryId` | `string \| null` | No | Deprecated alias for idempotencyKey, accepted for one release. idempotencyKey wins when both are present. |

## Responses

### `200` (`application/json`)

ThreadResult

Schema: `ThreadResult`

| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `threadId` | `integer` | Yes |  |
| `kickoff` | `string \| null` | No | Present when kickoff events were supplied. A failed kickoff still returns the created thread. Retry create or fork with the same idempotencyKey to reuse this thread and retry kickoff, or retry only its events with this threadId. A repeated key returns duplicate. |

Example:

```json
{
  "threadId": 0,
  "kickoff": "accepted"
}
```

### `400` (`application/json`)

DetachedInteractionRejectedError

Schema: `DetachedInteractionRejectedError`

| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `_tag` | `string` | Yes |  |
| `message` | `string` | Yes |  |

Example:

```json
{
  "_tag": "DetachedInteractionRejectedError",
  "message": "Reply with a one-line greeting."
}
```

### `401` (`application/json`)

AuthenticationError

Schema: `AuthenticationError`

| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `_tag` | `string` | Yes |  |
| `reason` | `string` | Yes |  |
| `description` | `string` | No |  |

Example:

```json
{
  "_tag": "AuthenticationError",
  "reason": "invalid_session",
  "description": "string"
}
```

### `402` (`application/json`)

OrganizationUnsubscribedError

Schema: `OrganizationUnsubscribedError`

| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `_tag` | `string` | Yes |  |
| `code` | `string` | Yes |  |

Example:

```json
{
  "_tag": "OrganizationUnsubscribedError",
  "code": "ORGANIZATION_UNSUBSCRIBED"
}
```

### `403` (`application/json`)

ActorUnauthorizedError | UnauthorizedError | IdentityMismatchError | RequestedOrganizationError

Schema: `ActorUnauthorizedError | UnauthorizedError | IdentityMismatchError | ...`

| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `$ (ActorUnauthorizedError)._tag` | `string` | Yes |  |
| `$ (UnauthorizedError)._tag` | `string` | Yes |  |
| `$ (UnauthorizedError).entity` | `string` | Yes |  |
| `$ (UnauthorizedError).action` | `string` | Yes |  |
| `$ (IdentityMismatchError)._tag` | `string` | Yes |  |
| `$ (RequestedOrganizationError)._tag` | `string` | Yes |  |
| `$ (RequestedOrganizationError).reason` | `string \| null` | Yes |  |

Example:

```json
{
  "_tag": "ActorUnauthorizedError"
}
```

### `404` (`application/json`)

ThreadForkCutoffNotFoundError | SessionNotFoundError

Schema: `ThreadForkCutoffNotFoundError | SessionNotFoundError`

| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `$ (ThreadForkCutoffNotFoundError)._tag` | `string` | Yes |  |
| `$ (ThreadForkCutoffNotFoundError).sourceMessageId` | `number` | Yes |  |
| `$ (SessionNotFoundError)._tag` | `string` | Yes |  |
| `$ (SessionNotFoundError).id` | `string` | Yes | TypeID with prefix "asess_". |

Example:

```json
{
  "_tag": "ThreadForkCutoffNotFoundError",
  "sourceMessageId": 1
}
```

### `409` (`application/json`)

ThreadCapacityError | ThreadForkCutoffUnsettledError | SessionArchivedError

Schema: `ThreadCapacityError | ThreadForkCutoffUnsettledError | SessionArchivedError`

| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `$ (ThreadCapacityError)._tag` | `string` | Yes |  |
| `$ (ThreadCapacityError).limit` | `number` | Yes |  |
| `$ (ThreadForkCutoffUnsettledError)._tag` | `string` | Yes |  |
| `$ (ThreadForkCutoffUnsettledError).sourceMessageId` | `number` | Yes |  |
| `$ (SessionArchivedError)._tag` | `string` | Yes |  |
| `$ (SessionArchivedError).id` | `string` | Yes | TypeID with prefix "asess_". |
| `$ (SessionArchivedError).eventAccepted` | `boolean` | No |  |
| `$ (SessionArchivedError).acceptedOrdinal` | `integer` | No |  |

Example:

```json
{
  "_tag": "ThreadCapacityError",
  "limit": 1
}
```

### `410` (`application/json`)

SessionRuntimeGoneError

Schema: `SessionRuntimeGoneError`

| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `_tag` | `string` | Yes |  |
| `id` | `string` | Yes | TypeID with prefix "asess_". |

Example:

```json
{
  "_tag": "SessionRuntimeGoneError",
  "id": "asess_01jd8z3k5q0b6f2m4r7t9v1x3c"
}
```

### `413` (`application/json`)

ThreadForkTooLargeError

Schema: `ThreadForkTooLargeError`

| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `_tag` | `string` | Yes |  |
| `payloadBytes` | `number` | Yes |  |
| `maxBytes` | `number` | Yes |  |

Example:

```json
{
  "_tag": "ThreadForkTooLargeError",
  "payloadBytes": 1,
  "maxBytes": 1
}
```

### `422` (`application/json`)

ThreadForkCutoffNotReplayableError

Schema: `ThreadForkCutoffNotReplayableError`

| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `_tag` | `string` | Yes |  |
| `sourceMessageId` | `number` | Yes |  |

Example:

```json
{
  "_tag": "ThreadForkCutoffNotReplayableError",
  "sourceMessageId": 1
}
```

### `429` (`application/json`)

RateLimitExceededError

Schema: `RateLimitExceededError`

| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `_tag` | `string` | Yes |  |
| `resource` | `string` | Yes | Rate-limited resource bucket the request was counted against. |
| `retryAfter` | `number` | Yes |  |

Example:

```json
{
  "_tag": "RateLimitExceededError",
  "resource": "string",
  "retryAfter": 1
}
```

### `500` (`application/json`)

InternalError

Schema: `InternalError`

| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `_tag` | `string` | Yes |  |

Example:

```json
{
  "_tag": "InternalError"
}
```

### `502` (`application/json`)

ActorActionError

Schema: `ActorActionError`

| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `_tag` | `string` | Yes |  |
| `code` | `string` | Yes |  |
| `acceptedEvents` | `integer` | No |  |
| `totalEvents` | `integer` | No |  |

Example:

```json
{
  "_tag": "ActorActionError",
  "code": "string",
  "acceptedEvents": -9007199254740991,
  "totalEvents": -9007199254740991
}
```

### `503` (`application/json`)

ActorUnavailableError

Schema: `ActorUnavailableError`

| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `_tag` | `string` | Yes |  |

Example:

```json
{
  "_tag": "ActorUnavailableError"
}
```

## Example Request

### cURL

```bash
curl -X POST 'https://api.thecompany.company/v1/sessions/{id}/threads/fork' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Content-Type: application/json' \
  -d @- <<'JSON'
{
  "sourceMessageId": 1
}
JSON
```

### TypeScript

```typescript
const response = await fetch('https://api.thecompany.company/v1/sessions/{id}/threads/fork', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
  "sourceMessageId": 1
}),
});
if (!response.ok) {
  throw new Error('HTTP ' + response.status);
}
const data = await response.json();
```
