# Update Session Chat

Source: https://recoupable.dev/docs/api-reference/sessions/patch-chat

Update session chat

## PATCH /api/sessions/{sessionId}/chats/{chatId}

Full OpenAPI specification: https://recoupable.dev/docs/spec/sessions.json

## Authentication

This operation requires one of the security alternatives in the specification below. Security scheme definitions are included where present in the published specification.

[Authentication guide](https://recoupable.dev/docs/authentication)

## Operation and referenced schemas

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "Recoup API - Sessions",
    "description": "Sessions — sandboxed runs of an LLM-driven agent with tool use, lifecycle hooks, and persistence. Each session pairs one Vercel Sandbox with one or more chat threads.",
    "license": {
      "name": "MIT"
    },
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://api.recoupable.dev"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    },
    {
      "BearerAuth": []
    }
  ],
  "paths": {
    "/api/sessions/{sessionId}/chats/{chatId}": {
      "patch": {
        "summary": "Update session chat",
        "description": "Applies a partial update to the chat. Body must include at least one of `title` or `modelId` and any provided value must be a non-empty string (whitespace is trimmed for `title`).",
        "parameters": [
          {
            "name": "sessionId",
            "in": "path",
            "required": true,
            "description": "The id of the parent session.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "chatId",
            "in": "path",
            "required": true,
            "description": "The id of the chat being updated.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateSessionChatRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Chat updated successfully.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpdateSessionChatResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid body — JSON parse failed, neither `title` nor `modelId` was provided, or one of them was empty.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized — invalid or missing API key / Bearer token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — the authenticated account does not own this session.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found — no session exists with the given id, the chat does not exist, or the chat belongs to a different session.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Server error — the chat could not be updated.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "UpdateSessionChatRequest": {
        "type": "object",
        "description": "Body for `PATCH /api/sessions/{sessionId}/chats/{chatId}`. At least one of `title` or `modelId` must be provided; whichever is provided is trimmed and must be non-empty after trimming.",
        "additionalProperties": false,
        "anyOf": [
          {
            "required": [
              "title"
            ]
          },
          {
            "required": [
              "modelId"
            ]
          }
        ],
        "properties": {
          "title": {
            "type": "string",
            "minLength": 1,
            "pattern": "\\S",
            "description": "New display title for the chat. Trimmed; must be non-empty after trimming."
          },
          "modelId": {
            "type": "string",
            "minLength": 1,
            "pattern": "\\S",
            "description": "AI Gateway model identifier the chat should be configured to use. Trimmed; must be non-empty after trimming."
          }
        }
      },
      "UpdateSessionChatResponse": {
        "type": "object",
        "required": [
          "chat"
        ],
        "properties": {
          "chat": {
            "$ref": "#/components/schemas/Chat"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "status",
          "error"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "error"
            ],
            "description": "Always `\"error\"` for error responses."
          },
          "error": {
            "type": "string",
            "description": "Human-readable error message."
          }
        }
      },
      "Chat": {
        "type": "object",
        "required": [
          "id",
          "sessionId",
          "title",
          "modelId",
          "createdAt",
          "updatedAt"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Chat id (nanoid)."
          },
          "sessionId": {
            "type": "string",
            "description": "Owning session id."
          },
          "title": {
            "type": "string",
            "description": "Display title for the chat. The initial chat created with a session is titled `New chat`."
          },
          "modelId": {
            "type": "string",
            "description": "AI Gateway model identifier the chat is configured to use (e.g. `openai/gpt-5.4`)."
          },
          "activeStreamId": {
            "type": "string",
            "nullable": true,
            "description": "Id of an in-flight assistant stream, if one is active."
          },
          "lastAssistantMessageAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "Timestamp of the most recent assistant message in this chat."
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    },
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key"
      },
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    }
  }
}
```
