> ## Documentation Index
> Fetch the complete documentation index at: https://docs.keebai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# POST /v1/blocks/{id}/versions/{versionId}/restore

> Restore an old version by appending it as a new current version. Nothing is overwritten.

Brings back an earlier version of a block's content.

It does this by **copying** that version into a new one at the top of the history and pointing the block at it. Nothing is rewound and nothing is lost: after restoring version 2 onto a block at version 5, the block is at version 6 and versions 1 through 5 are still there.

## Endpoint

```
POST https://api.keebai.com/v1/blocks/{id}/versions/{versionId}/restore
```

## Required scope

`assistants:write`

## Headers

| Header          | Required | Value                    |
| --------------- | -------- | ------------------------ |
| `Authorization` | Yes      | `Bearer kbai_pk_<token>` |

## Path parameters

| Parameter   | Type     | Description                                                      |
| ----------- | -------- | ---------------------------------------------------------------- |
| `id`        | `string` | `ObjectId` of the block.                                         |
| `versionId` | `string` | `ObjectId` of the version to restore. Must belong to that block. |

No body.

## Example request

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST \
    https://api.keebai.com/v1/blocks/6650bbbb2222cccc3333dddd/versions/6650ffff4444aaaa5555bbbb/restore \
    -H "Authorization: Bearer kbai_pk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  ```

  ```js JavaScript theme={null}
  const base = "https://api.keebai.com/v1/blocks/6650bbbb2222cccc3333dddd";
  const auth = { Authorization: `Bearer ${process.env.KEEBAI_API_TOKEN}` };

  // Roll back to the version before the current one.
  const { data } = await (await fetch(`${base}/versions`, { headers: auth })).json();
  const previous = data.find((v) => !v.is_current);

  const resp = await fetch(`${base}/versions/${previous._id}/restore`, {
    method: "POST",
    headers: auth,
  });
  const { content } = await resp.json();
  ```

  ```python Python theme={null}
  import os, requests

  resp = requests.post(
      "https://api.keebai.com/v1/blocks/6650bbbb2222cccc3333dddd"
      "/versions/6650ffff4444aaaa5555bbbb/restore",
      headers={"Authorization": f"Bearer {os.environ['KEEBAI_API_TOKEN']}"},
      timeout=10,
  )
  resp.raise_for_status()
  content = resp.json()["content"]
  ```
</CodeGroup>

## Response

### 201 Created

The newly created version, in the same shape as [`GET /v1/blocks/{id}/content`](/dev/endpoints/blocks-content-get). Note the `version_number` is the new one, and the content is the restored one.

```json theme={null}
{
  "content": {
    "block_id": "6650bbbb2222cccc3333dddd",
    "version_id": "6650ffff4444aaaa5555eeee",
    "version_number": 6,
    "edit_mode": "free",
    "content": "1. Saludar.\n2. Preguntar el servicio.",
    "created_at": "2026-07-26T22:01:47.330Z"
  }
}
```

### 401 Unauthorized

Missing, invalid, revoked, or expired token.

### 403 Forbidden

The token does not have the `assistants:write` scope.

### 404 Not Found

The block does not exist in the token's company and project, or `error.code` is `BLOCK_VERSION_NOT_FOUND` because the version does not exist or belongs to a different block.

### 409 Conflict

`error.code` is `BLOCK_TYPE_NOT_WRITABLE`. The block is one of the five catalogue types, which the portal owns.

### 502 Bad Gateway

The assistant service is unreachable.

## Operational notes

* **Restoring is a write, so it needs `assistants:write`** and is subject to the same type restriction as [saving content](/dev/endpoints/blocks-content-save): the five catalogue types refuse it.
* **Restoring is not idempotent.** Calling it twice appends two identical versions. Harmless, but the history grows.
* **Assistants pinned to another version are unaffected.** Restoring moves the block's current version; a pinned assistant keeps rendering what it was pinned to.
* **Restoring is reversible by restoring again.** The version you just moved away from is still in the history with its own id.
* **Check before you restore.** [Read the version](/dev/endpoints/blocks-version-get) first — the history list deliberately carries no content, so `version_number` alone tells you nothing about what you are bringing back.


## OpenAPI

````yaml POST /v1/blocks/{id}/versions/{versionId}/restore
openapi: 3.0.0
info:
  title: Keebai Public API
  description: Superficie pública REST autenticada con Personal Access Tokens (PAT).
  version: 1.0.0
  contact: {}
servers:
  - url: https://api.keebai.com
    description: Production
security: []
tags: []
paths:
  /v1/blocks/{id}/versions/{versionId}/restore:
    post:
      tags:
        - blocks
      summary: Restaurar una version
      description: >-
        Vuelve a una version anterior copiandola como version nueva y vigente.
        No pisa ni borra nada del historial.
      operationId: PublicBlocksController_restoreVersion
      parameters:
        - name: id
          required: true
          in: path
          schema:
            type: string
        - name: versionId
          required: true
          in: path
          schema:
            type: string
      responses:
        '201':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicBlockContentEnvelopeDto'
      security:
        - PAT: []
components:
  schemas:
    PublicBlockContentEnvelopeDto:
      type: object
      properties:
        content:
          $ref: '#/components/schemas/PublicBlockContentDto'
      required:
        - content
    PublicBlockContentDto:
      type: object
      properties:
        content:
          type: string
          maxLength: 100000
          description: >-
            Contenido completo del bloque en texto. Reemplaza al anterior
            creando una version nueva.
          example: |-
            Sos el asistente de una barberia.
            - Tuteas al cliente.
      required:
        - content
  securitySchemes:
    PAT:
      scheme: bearer
      bearerFormat: kbai_pk_<hex>
      type: http
      description: >-
        Personal Access Token con prefijo `kbai_pk_`. Generar desde el portal
        con permiso `developer.manage_tokens`.

````