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

# Finalize the visible text of stored messages

PATCH https://api.runtype.com/v1/client/conversations/{id}/display-projections
Content-Type: application/json

Record what a human actually saw for messages this conversation already stores. A chat client can only compute an assistant message's final visible text after the stream closes and its own parsers, postprocessors, and plugins have run; this is the channel for sending that back, so the transcript reopens showing what the visitor read rather than the model-channel payload. It is projection-only: it can fill or replace `displayContent` and nothing else, never creating a message or touching model content, role, ordering, timestamps, count, ownership, or title. The batch applies all-or-nothing, and the write is guarded by a compare-and-swap on `conversationRevision`, so it can never overwrite a turn the chat path persisted concurrently. Replaying an identical projection is a no-op that performs no write and returns the same `conversationRevision`. A genuinely changed projection advances the revision and refreshes the list `preview`, but deliberately does NOT change `updatedAt` — a closing tab must not reorder the visitor's history. Authorization is exact: the live session must be bound to this conversation, on top of the visitor secret. Small and bounded on purpose, so a client can send it with `keepalive: true` on page exit.

Reference: https://docs.runtype.com/api-reference/runtype-api/client-runtime/finalize-the-visible-text-of-stored-messages

## Servers

- `https://api.runtype.com` (Production, default)
- `https://api.runtype-staging.com` (Staging)

## Request

### Path parameters

- `id` (string, required) — Conversation id — must be this session’s own.

### Query parameters

- `sessionId` (string, required) — Client session id from /client/init.

### Headers

- `x-visitor-token` (string, required) — The browser's anonymous visitor secret (`cvt_…`) returned by `/client/init`. It is what scopes the request to one visitor's own conversations, so a request without it is refused. Sent as a header so it never lands in access logs or `Referer`.
- `x-identity-proof` (string, optional) — Optional fresh hosted end-user identity proof. When admitted and already bound to the presented visitor, expands the request from this exact browser to sibling visitors for the same verified person. Without it, even a previously bound visitor remains exact-browser scoped.

### Body (application/json)

This endpoint expects an object.

- `messages` (list of V1ClientConversationsIdDisplayProjectionsPatchRequestBodyContentApplicationJsonSchemaMessagesItems, required) — Projections to finalize, applied atomically. Total `displayContent` across the batch is capped at 49152 characters so the request fits the browser keepalive budget.

## Response

### 200

Projections finalized (or already current).

- `conversationRevision` (string, required) — The conversation's change token after this call. Unchanged when the projections were already current, so a client can replay a lost finalization safely. Compare for equality only.

## Errors

### 400 Bad Request Error

Missing or malformed `sessionId`, or a body that exceeds the per-message / per-batch projection bounds

- `error` (string, required)
- `details` (list of ErrorDetailsItems, optional)

### 401 Unauthorized Error

Session expired, or missing/invalid visitor token

- `error` (string, required)
- `details` (list of ErrorDetailsItems, optional)

### 403 Forbidden Error

Client token inactive or origin mismatch

- `error` (string, required)
- `details` (list of ErrorDetailsItems, optional)

### 404 Not Found Error

This session is not on that conversation, the visitor does not own it, or the batch named a message the conversation does not hold. One non-enumerating answer covers all three: the route never confirms which.

- `error` (string, required)
- `details` (list of ErrorDetailsItems, optional)

### 409 Conflict Error

The conversation changed while the projections were being written and the compare-and-swap kept losing (`conversation_modified`). Nothing was written. Non-fatal: retry, or ignore it and let the next chat turn re-carry the projections through the repair path.

- `error` (string, required)
- `details` (list of ErrorDetailsItems, optional)

### 429 Too Many Requests Error

Rate limit exceeded for this client token or session. The response carries a `Retry-After` header with the advisory wait in seconds.

- `error` (string, required)
- `details` (list of ErrorDetailsItems, optional)

### 500 Internal Server Error

Internal server error

- `error` (string, required)
- `details` (list of ErrorDetailsItems, optional)

## Types

### V1ClientConversationsIdDisplayProjectionsPatchRequestBodyContentApplicationJsonSchemaMessagesItems

- `displayContent` (string, required) — The final text a human saw for that message. An empty string is a valid, deliberate empty projection.
- `id` (string, required) — Id of a message this conversation ALREADY stores. An id it does not hold fails the whole batch.

### ErrorDetailsItems

- `message` (string, required)
- `code` (string, optional) — Stable Runtype validation code (e.g. MISSING_REQUIRED_FIELD, INVALID_ENUM).
- `path` (string, optional) — Dotted JSON path to the offending field.
- `suggestion` (string, optional) — Actionable hint (allowed values, accepted range, …).

## Examples

**Request**

```json
{
  "messages": [
    {
      "displayContent": "Your order ships on Tuesday.",
      "id": "msg_assistant_1"
    }
  ]
}
```

**Response**

```json
{
  "conversationRevision": "string"
}
```

**SDK Code**

```python Finalize the last assistant turn as the page unloads
import requests

url = "https://api.runtype.com/v1/client/conversations/id/display-projections"

querystring = {"sessionId":"sessionId"}

payload = { "messages": [
        {
            "displayContent": "Your order ships on Tuesday.",
            "id": "msg_assistant_1"
        }
    ] }
headers = {
    "x-visitor-token": "x-visitor-token",
    "Content-Type": "application/json"
}

response = requests.patch(url, json=payload, headers=headers, params=querystring)

print(response.json())
```

```javascript Finalize the last assistant turn as the page unloads
const url = 'https://api.runtype.com/v1/client/conversations/id/display-projections?sessionId=sessionId';
const options = {
  method: 'PATCH',
  headers: {'x-visitor-token': 'x-visitor-token', 'Content-Type': 'application/json'},
  body: '{"messages":[{"displayContent":"Your order ships on Tuesday.","id":"msg_assistant_1"}]}'
};

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

```go Finalize the last assistant turn as the page unloads
package main

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

func main() {

	url := "https://api.runtype.com/v1/client/conversations/id/display-projections?sessionId=sessionId"

	payload := strings.NewReader("{\n  \"messages\": [\n    {\n      \"displayContent\": \"Your order ships on Tuesday.\",\n      \"id\": \"msg_assistant_1\"\n    }\n  ]\n}")

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

	req.Header.Add("x-visitor-token", "x-visitor-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 Finalize the last assistant turn as the page unloads
require 'uri'
require 'net/http'

url = URI("https://api.runtype.com/v1/client/conversations/id/display-projections?sessionId=sessionId")

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

request = Net::HTTP::Patch.new(url)
request["x-visitor-token"] = 'x-visitor-token'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"messages\": [\n    {\n      \"displayContent\": \"Your order ships on Tuesday.\",\n      \"id\": \"msg_assistant_1\"\n    }\n  ]\n}"

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

```java Finalize the last assistant turn as the page unloads
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.patch("https://api.runtype.com/v1/client/conversations/id/display-projections?sessionId=sessionId")
  .header("x-visitor-token", "x-visitor-token")
  .header("Content-Type", "application/json")
  .body("{\n  \"messages\": [\n    {\n      \"displayContent\": \"Your order ships on Tuesday.\",\n      \"id\": \"msg_assistant_1\"\n    }\n  ]\n}")
  .asString();
```

```php Finalize the last assistant turn as the page unloads
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PATCH', 'https://api.runtype.com/v1/client/conversations/id/display-projections?sessionId=sessionId', [
  'body' => '{
  "messages": [
    {
      "displayContent": "Your order ships on Tuesday.",
      "id": "msg_assistant_1"
    }
  ]
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-visitor-token' => 'x-visitor-token',
  ],
]);

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

```csharp Finalize the last assistant turn as the page unloads
using RestSharp;

var client = new RestClient("https://api.runtype.com/v1/client/conversations/id/display-projections?sessionId=sessionId");
var request = new RestRequest(Method.PATCH);
request.AddHeader("x-visitor-token", "x-visitor-token");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"messages\": [\n    {\n      \"displayContent\": \"Your order ships on Tuesday.\",\n      \"id\": \"msg_assistant_1\"\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Finalize the last assistant turn as the page unloads
import Foundation

let headers = [
  "x-visitor-token": "x-visitor-token",
  "Content-Type": "application/json"
]
let parameters = ["messages": [
    [
      "displayContent": "Your order ships on Tuesday.",
      "id": "msg_assistant_1"
    ]
  ]] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.runtype.com/v1/client/conversations/id/display-projections?sessionId=sessionId")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PATCH"
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()
```