> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.astropods.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.astropods.com/_mcp/server.

# Switch chat branch

PUT https://astropods.com/api/v1/deployments/{deploymentId}/chat/conversations/{conversationId}/branch
Content-Type: application/json

Shows another version of a conversation. A conversation branches when a user
edits a message they sent: the old message and its replies stay as another
version. This makes the newest message under `message_id` the end of the
conversation and returns the thread in the same shape as getting the
conversation. Returns 400 `edit_unsupported` when the agent does not support
edits, 404 for a message outside the conversation, and 409 `turn_in_progress`
while a reply is in progress.


Reference: https://docs.astropods.com/api-reference/astropods-api/chat/switch-chat-branch

## Authentication

- `Authorization` header (bearer token, required) — OAuth 2.0 device flow or platform session token

## Request

### Path parameters

- `deploymentId` (string, required) — Deployment ID
- `conversationId` (string, required) — Conversation ID (client-chosen UUID v4)

### Body (application/json)

This endpoint expects a ChatBranchRequest.

- `message_id` (string, required) — A message on the version to show. The newest message under it becomes the end of the conversation.

## Response

### 200

The conversation on the chosen branch

- `conversation_id` (string, optional)
- `title` (string, optional)
- `updated_at` (datetime, optional)
- `assistant_streaming` (boolean, optional)
- `messages` (list of ChatMessage, optional) — The conversation's active branch, oldest first.
- `has_more` (boolean, optional) — Present when a page was returned; more (older) messages exist.
- `oldest_seq` (integer, optional) — Sequence number of the oldest message in this page (pagination cursor).

## Errors

### 400 Bad Request Error

Invalid request body or parameters

- `error` (string, optional)
- `details` (string, optional)

### 401 Unauthorized Error

Authentication required

- `error` (string, optional)
- `details` (string, optional)

### 403 Forbidden Error

Insufficient permissions for this account

- `error` (string, optional)
- `details` (string, optional)

### 404 Not Found Error

Resource not found

- `error` (string, optional)
- `details` (string, optional)

### 409 Conflict Error

A reply is in progress. The body carries `turn_in_progress`.

- `error` (string, optional)
- `details` (string, optional)

### 500 Internal Server Error

Server error

- `error` (string, optional)
- `details` (string, optional)

## Types

### ChatMessage

- `id` (string, optional)
- `role` (enum, optional)
  - Allowed values: `user`, `assistant`
- `content` (string, optional)
- `attachments` (list of ChatFileAttachment, optional)
- `branches` (list of string, optional) — Present when the message has other versions: the ids of this message and its alternatives, oldest first. Switch versions with the branch endpoint.

### ChatFileAttachment

- `key` (string, required)
- `name` (string, required) — User-facing filename.
- `content_type` (string, required)
- `size` (long, required)

## Examples

**Request**

```json
{
  "message_id": "string"
}
```

**Response**

```json
{
  "conversation_id": "string",
  "title": "string",
  "updated_at": "2024-01-15T09:30:00Z",
  "assistant_streaming": true,
  "messages": [
    {
      "id": "string",
      "role": "user",
      "content": "string",
      "attachments": [
        {
          "key": "string",
          "name": "string",
          "content_type": "string",
          "size": 1
        }
      ],
      "branches": [
        "string"
      ]
    }
  ],
  "has_more": true,
  "oldest_seq": 1
}
```

**SDK Code**

```python
import requests

url = "https://astropods.com/api/v1/deployments/deploymentId/chat/conversations/conversationId/branch"

payload = { "message_id": "string" }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.put(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://astropods.com/api/v1/deployments/deploymentId/chat/conversations/conversationId/branch';
const options = {
  method: 'PUT',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"message_id":"string"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://astropods.com/api/v1/deployments/deploymentId/chat/conversations/conversationId/branch"

	payload := strings.NewReader("{\n  \"message_id\": \"string\"\n}")

	req, _ := http.NewRequest("PUT", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://astropods.com/api/v1/deployments/deploymentId/chat/conversations/conversationId/branch")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"message_id\": \"string\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.put("https://astropods.com/api/v1/deployments/deploymentId/chat/conversations/conversationId/branch")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"message_id\": \"string\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://astropods.com/api/v1/deployments/deploymentId/chat/conversations/conversationId/branch', [
  'body' => '{
  "message_id": "string"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://astropods.com/api/v1/deployments/deploymentId/chat/conversations/conversationId/branch");
var request = new RestRequest(Method.PUT);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"message_id\": \"string\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["message_id": "string"] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://astropods.com/api/v1/deployments/deploymentId/chat/conversations/conversationId/branch")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```