---
title: "Update Chat Files"
method: PATCH
path: "/chats/{chatId}/files"
tags: ["Chats"]
---

# Update Chat Files

`PATCH /chats/{chatId}/files`

Creates, updates, or deletes files for a chat. Pass null to delete. This requires the chat's preview to be running.

## Path parameters

- `chatId` string, required — The unique identifier of the chat.

## Request body

- object
  - `files` object[], required — The files to create, update, or delete. Each path must be unique.
    - `path` string, required — Project-relative file path, e.g. "app/page.tsx".
    - `content` string, nullable, required — New file content. Pass `null` to delete the file at this path.

## Response `200`

The messages created to record the file edit.

- object — The messages created to record the file edit.
  - `messages` object[], required — The user and assistant messages created by the edit, in chronological order.
    - `id` string, required — Unique message identifier.
    - `chatId` string, required — ID of the chat this message belongs to.
    - `role` 'user' | 'assistant', required — Who produced this message.
    - `createdAt` string, date-time, required — ISO timestamp when the message was created.
    - `updatedAt` string, date-time, required — ISO timestamp when the message was last updated.
    - `content` string, required — The trailing prose of the message — the agent’s closing summary, or the user’s message text. Empty string when there is no closing prose.
    - `parts` union[], required — Ordered list of parts that make up the message. Iterate to render the full narrative including thinking, file operations, tool calls, and prose.
      - union — A single entry in the ordered narrative of a message. Iterate `parts` in order to render the full transcript.
        - object — A block of text output by the agent.
          - `type` 'text', required
          - `text` string, required — Markdown prose written by the agent or user.
          - `startedAt` string, date-time — ISO timestamp when this part began.
          - `finishedAt` string, date-time — ISO timestamp when this part completed.
        - object — Extended thinking output by the agent.
          - `type` 'thinking', required
          - `text` string, required — The agent's reasoning trace.
          - `startedAt` string, date-time — ISO timestamp when this part began.
          - `finishedAt` string, date-time — ISO timestamp when this part completed.
        - object — Files read by the agent.
          - `type` 'file-read', required
          - `paths` string[], required — The file paths the agent read in this step.
          - `startedAt` string, date-time — ISO timestamp when this part began.
          - `finishedAt` string, date-time — ISO timestamp when this part completed.
        - object — The agent created, modified, deleted, renamed, or patched a file.
          - `type` 'file-edit', required
          - `operation` 'create' | 'update' | 'delete' | 'rename' | 'patch', required — The type of file edit performed.
          - `path` string, required — The target file path.
          - `toPath` string — The new path when operation is "rename".
          - `startedAt` string, date-time — ISO timestamp when this part began.
          - `finishedAt` string, date-time — ISO timestamp when this part completed.
        - object — The agent searched for something.
          - `type` 'search', required
          - `scope` 'repo' | 'web', required — Whether the agent searched the repository or the web.
          - `query` string, required — The search query.
          - `startedAt` string, date-time — ISO timestamp when this part began.
          - `finishedAt` string, date-time — ISO timestamp when this part completed.
        - object — The agent ran a shell command.
          - `type` 'bash', required
          - `command` string, required — The shell command that was executed.
          - `output` string — Combined stdout/stderr captured from the terminal. May be empty if the command produced no output.
          - `exitCode` integer, nullable — Process exit code, when available. Reserved for future use; currently always omitted.
          - `isDangerous` boolean — True if the command was flagged as potentially dangerous and required explicit user approval.
          - `timeoutMs` integer — Command timeout in milliseconds, when configured.
          - `startedAt` string, date-time — ISO timestamp when this part began.
          - `finishedAt` string, date-time — ISO timestamp when this part completed.
        - object — The agent invoked a tool (MCP, integration, or other dynamic tool). For shell commands, use the "bash" part instead.
          - `type` 'tool-call', required
          - `name` string, required — The name of the tool that was invoked (e.g. an MCP tool name or built-in tool identifier).
          - `input` unknown
          - `output` unknown
          - `status` 'ok' | 'error', required — Whether the tool call succeeded or returned an error.
          - `suggestedPermissions` object[] — Present when the agent is blocked waiting for you to approve this tool call (for example, running a setup or migration script). Pass these objects back unchanged as the `permissions` of a `confirmed-permissions` task to approve. Omitted once the tool has run.
            - `type` 'ALLOW_DYNAMIC_TOOL_STRICT', required — Permission grant type.
            - `toolName` string, required — The tool this permission authorizes.
            - `input` unknown
            - `taskNameActive` string, nullable — Internal label for the in-progress task. Pass back unchanged.
            - `taskNameComplete` string, nullable — Internal label for the completed task. Pass back unchanged.
            - `userMessage` string — Optional message associated with the permission.
          - `startedAt` string, date-time — ISO timestamp when this part began.
          - `finishedAt` string, date-time — ISO timestamp when this part completed.
        - object — A typed escape hatch for agent actions that don’t fit the other part types. Forward-compatible: new action types may appear without API version changes.
          - `type` 'agent-action', required
          - `name` string, required — Stable identifier for the action (e.g. "generate_image", "manage_todos", "diagnostics"). See documentation for the registry of known names.
          - `summary` string, required — A short human-readable summary of what happened. Always populated so clients can render something even without knowing the action name.
          - `data` union — Structured payload for input-requesting actions. Present on `ask_user_questions`, `exit_plan_mode`, `get_or_request_integration`, and `configure_vercel_connect` parts when the agent is waiting on you; narrow by the part `name`. Omitted for actions that do not carry structured data.
            - object — Structured payload for an `ask_user_questions` agent action.
              - …
            - object — Structured payload for an `exit_plan_mode` agent action.
              - …
            - object — Structured payload for a `get_or_request_integration` agent action.
              - …
            - union
              - …
          - `startedAt` string, date-time — ISO timestamp when this part began.
          - `finishedAt` string, date-time — ISO timestamp when this part completed.
    - `finishReason` 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other', nullable, required — The reason why message generation finished, including standard completion reasons and error states.
    - `restorable` boolean, required — True when this is an assistant message that produced restorable code and is not the currently active code.
    - `attachments` object[] — Files attached to this message.
      - `url` string, required — URL to the attachment.
      - `name` string — Original filename, when available.
      - `contentType` string — MIME type.
      - `size` integer — Size in bytes.
    - `authorId` string, nullable, required — ID of the user who authored a user message; null for assistant messages.
    - `usage` object, required — Token usage and credit cost. All values are zero on user messages and on assistant messages that have not yet generated tokens.
      - `tokens` object, required — Token counts for this message.
        - `input` number, required — Prompt input value (non-cached).
        - `output` number, required — Completion output value.
        - `cacheRead` number, required — Cache-read input value.
        - `cacheWrite` number, required — Cache-write input value.
        - `total` number, required — Sum of input, output, cacheRead, and cacheWrite.
      - `creditsCost` object, required — Credit cost for this message.
        - `input` number, required — Prompt input value (non-cached).
        - `output` number, required — Completion output value.
        - `cacheRead` number, required — Cache-read input value.
        - `cacheWrite` number, required — Cache-write input value.
        - `total` number, required — Sum of input, output, cacheRead, and cacheWrite.

## Other responses

- `401` — Response for status 401
- `403` — Response for status 403
- `404` — Response for status 404
- `409` — Response for status 409
- `422` — Response for status 422
- `500` — Response for status 500

---

[API](https://skmtc.net/vercel/apis/v0-platform-api-beta.md) · [All operations](https://skmtc.net/vercel/apis/v0-platform-api-beta/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/vercel/v0-platform-api-beta/versions/7c7a496f8022/schema)
