# Restore a version

POST

/v1/files/{fileId}/versions/{version}/restore

```sh
curl --request POST \
  --url https://example.com/v1/files/2489E9AD-2EE2-8E00-8EC9-32D5F69181C0/versions/1/restore \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{ "expectedVersion": 1 }'
```

Makes a new version, Latest, from this version’s bytes, with `restoredFrom` set. Nothing is removed. A deleted or purged version is `404 file-version-not-found`. With `expectedVersion`, a Latest that isn’t it is `409 file-version-conflict`. A version whose bytes are already Latest’s adds none (`200`, `created: false`). Needs `write` on the file’s project.

## Authorizations

- **[bearerAuth](https://docs.kindgi.com/v0.8.1/reference/api.md#bearerauth)**

## Parameters

### Path Parameters

**fileId**

required

string format: uuid

The file’s id: the `blobId` of its version 1’s bytes.

**version**

required

integer

\>= 1

A version number from 1.

### Header Parameters

**Idempotency-Key**

string

\>= 1 characters

Caller-supplied idempotency key, scoped to the caller: the same key from someone else in the workspace is their own request (from 0.1.5). Retries with the same key return the original response byte-identical (per `docs/API-ROUTE-CONVENTIONS.md` §3.1). A retry sent while the first request still runs is answered `409 idempotency-key-in-flight` with `Retry-After`, on a runtime whose store holds keys (from 0.1.5); retry after it, and you get the first request’s answer. An answer that carries a secret (a new API key or public run token, a session token, a generated signing secret) isn’t kept: a retry gets `409 idempotency-key-replay-withheld`, with the first request’s status and when it succeeded (from 0.1.5). A request whose key store can’t be read before it runs is answered `503 idempotency-store-unavailable` with `Retry-After`: nothing ran, so retry with the same key (from 0.3.0).

## Request Body

application/json

object

**expectedVersion**

As on adding a version: when Latest isn’t it, nothing is written.

integer

\>= 1

##### Examplegenerated

```json
{
  "expectedVersion": 1
}
```

## Responses

### 200

The bytes were already Latest’s: Latest, with `created: false`.

application/json

object

**version**

required

One version of a file. Numbers start at 1, only grow, and are never reused. A deleted or purged version keeps its record, so the runs that used it still name it.

object

**fileId**

required

The file’s id: the `blobId` of its version 1’s bytes, which names the file through every later version.

string

**version**

required

integer

\>= 1

**blobId**

required

The stored bytes. Two versions of one file can share them.

string

**name**

required

The file’s name when this version was made.

string

**contentType**

required

MIME type, as the writer declared it.

string

**size**

required

integer

**hash**

required

Sha256 of the bytes, hex-encoded, lowercase.

string

/^\[0-9a-f]{64}$/

**tags**

required

Labels the writer gave this version.

object

**_key_**

additional properties

string

**parentVersion**

Latest when this version was made. Absent on version 1.

integer

\>= 1

**restoredFrom**

The version a restore copied the bytes of.

integer

\>= 1

**madeVia**

required

How it was made: a person’s or a key’s upload, a restore, a run’s tool, or a run’s model.

string

Allowed values: upload restore tool model

**createdBy**

Who made it: `user:<id>` or `service_account:<id>`, or `run:<id>` for a run’s tool or model.

string

**runId**

The run that made it, when one did.

string format: uuid

**callKey**

The run’s tool call that made it.

string

**toolId**

The tool that made it.

string

**createdAt**

required

string format: date-time

**supersededAt**

When a newer version replaced it as Latest. Absent on Latest: when Latest is deleted, the version that’s Latest again has none.

string format: date-time

**pin**

A version’s keep mark: it can’t be deleted, and retention never purges it.

object

**by**

required

Who pinned it: `user:<id>` or `service_account:<id>`.

string

**at**

required

string format: date-time

**reason**

string

**deletedAt**

string format: date-time

**purgedAt**

When retention dropped its bytes (the `file_version` domain). Its number, hash, size and maker stay.

string format: date-time

**created**

required

`false` when the bytes were already Latest’s: no version was added, and `version` is Latest.

boolean

##### Example

```json
{
  "version": {
    "madeVia": "upload"
  }
}
```

### 201

The new version.

application/json

object

**version**

required

One version of a file. Numbers start at 1, only grow, and are never reused. A deleted or purged version keeps its record, so the runs that used it still name it.

object

**fileId**

required

The file’s id: the `blobId` of its version 1’s bytes, which names the file through every later version.

string

**version**

required

integer

\>= 1

**blobId**

required

The stored bytes. Two versions of one file can share them.

string

**name**

required

The file’s name when this version was made.

string

**contentType**

required

MIME type, as the writer declared it.

string

**size**

required

integer

**hash**

required

Sha256 of the bytes, hex-encoded, lowercase.

string

/^\[0-9a-f]{64}$/

**tags**

required

Labels the writer gave this version.

object

**_key_**

additional properties

string

**parentVersion**

Latest when this version was made. Absent on version 1.

integer

\>= 1

**restoredFrom**

The version a restore copied the bytes of.

integer

\>= 1

**madeVia**

required

How it was made: a person’s or a key’s upload, a restore, a run’s tool, or a run’s model.

string

Allowed values: upload restore tool model

**createdBy**

Who made it: `user:<id>` or `service_account:<id>`, or `run:<id>` for a run’s tool or model.

string

**runId**

The run that made it, when one did.

string format: uuid

**callKey**

The run’s tool call that made it.

string

**toolId**

The tool that made it.

string

**createdAt**

required

string format: date-time

**supersededAt**

When a newer version replaced it as Latest. Absent on Latest: when Latest is deleted, the version that’s Latest again has none.

string format: date-time

**pin**

A version’s keep mark: it can’t be deleted, and retention never purges it.

object

**by**

required

Who pinned it: `user:<id>` or `service_account:<id>`.

string

**at**

required

string format: date-time

**reason**

string

**deletedAt**

string format: date-time

**purgedAt**

When retention dropped its bytes (the `file_version` domain). Its number, hash, size and maker stay.

string format: date-time

**created**

required

`false` when the bytes were already Latest’s: no version was added, and `version` is Latest.

boolean

##### Example

```json
{
  "version": {
    "madeVia": "upload"
  }
}
```

### 400

Malformed request body.

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

### 401

Missing / malformed / expired / revoked bearer token.

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

### 403

No `write` on its project (`permission-denied`).

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

### 404

`file-not-found` as on the file; or `file-version-not-found`: no such version, or, for its bytes, a restore or a pin, one deleted or purged.

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

### 409

`file-version-conflict`: `expectedVersion` isn’t Latest (`details.expectedVersion`, `details.latestVersion`). Nothing was written. Or `idempotency-key-in-flight` (with `Retry-After`): a request with the same `Idempotency-Key` still runs, so this one wasn’t run; send it again after `Retry-After` to get that request’s answer.

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

#### Headers

**Retry-After**

integer

\>= 1

Whole seconds to wait before sending the request again, at least 1. Sent with the codes the answer names as sending it, so it may be absent.

### 413

The request body is over the API’s limit (`request-too-large`; `details.maxBytes` says how much).

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

### 429

`rate-limit-exceeded` with `details.limit: "api-requests"`, on a runtime that sets workspace limits (Kindgi Cloud): this workspace’s limit on API requests a minute is reached, so the request wasn’t run; `Retry-After` says when to send it again.

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

#### Headers

**Retry-After**

integer

\>= 1

Whole seconds to wait before sending the request again, at least 1. Sent with the codes the answer names as sending it, so it may be absent.

### 500

Server error (unmapped domain code or framework crash).

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

### 503

The `Idempotency-Key` store (`idempotency-store-unavailable`) or the authorization store (`authz-backend-unavailable`) couldn’t be reached before the request ran, or the database was too busy for its authorization check (`database-busy`), so nothing was changed; `Retry-After` (whole seconds) says when to try again with the same key. Or `tenant-state-unavailable` (with `Retry-After`), on a runtime serving many workspaces: the workspace’s state couldn’t be read, so nothing was changed.

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

#### Headers

**Retry-After**

integer

\>= 1

Whole seconds to wait before sending the request again, at least 1. Sent with the codes the answer names as sending it, so it may be absent.

## See also

- [`GET /v1/files/{fileId}`: Get a file](https://docs.kindgi.com/v0.8.1/reference/api/operations/filesget.md)
- [`DELETE /v1/files/{fileId}`: Delete a file](https://docs.kindgi.com/v0.8.1/reference/api/operations/filesdelete.md)
- [`GET /v1/files/{fileId}/versions`: List a file's versions](https://docs.kindgi.com/v0.8.1/reference/api/operations/filesversionslist.md)
- [`POST /v1/files/{fileId}/versions`: Add a version](https://docs.kindgi.com/v0.8.1/reference/api/operations/filesversionsadd.md)
- [Error code `authz-backend-unavailable`](https://docs.kindgi.com/v0.8.1/reference/errors.md#authz-backend-unavailable)
- [Error code `database-busy`](https://docs.kindgi.com/v0.8.1/reference/errors.md#database-busy)
- [Error code `file-not-found`](https://docs.kindgi.com/v0.8.1/reference/errors.md#file-not-found)
- [Error code `file-version-conflict`](https://docs.kindgi.com/v0.8.1/reference/errors.md#file-version-conflict)
- [Error code `file-version-not-found`](https://docs.kindgi.com/v0.8.1/reference/errors.md#file-version-not-found)
- [Error code `idempotency-key-in-flight`](https://docs.kindgi.com/v0.8.1/reference/errors.md#idempotency-key-in-flight)
- [Error code `idempotency-store-unavailable`](https://docs.kindgi.com/v0.8.1/reference/errors.md#idempotency-store-unavailable)
- [Error code `permission-denied`](https://docs.kindgi.com/v0.8.1/reference/errors.md#permission-denied)
- [Error code `rate-limit-exceeded`](https://docs.kindgi.com/v0.8.1/reference/errors.md#rate-limit-exceeded)
- [Error code `request-too-large`](https://docs.kindgi.com/v0.8.1/reference/errors.md#request-too-large)
- [Error code `tenant-state-unavailable`](https://docs.kindgi.com/v0.8.1/reference/errors.md#tenant-state-unavailable)
- [Every error code](https://docs.kindgi.com/v0.8.1/reference/errors.md)
