# client.files.versions

> client.files.versions — the files.versions operations.

`client.files.versions` — the `files.versions` operations.

On `AsyncKindgi` every method is the same, awaited.

## `client.files.versions.list()`

```python signature
list(
    file_id: str | UUID,
    /,
    *,
    limit: int | None = None,
    cursor: str | None = None,
    timeout: float | None = None,
) -> FileVersionCollectionPage
```

List a file's versions. `GET /v1/files/{fileId}/versions`

Cursor-paginated, newest first. Every version, deleted and purged ones included: a number is never left out of the history. An own file shows all its versions, including ones others added. Needs `read` on the file's project, or `run` there for a file of the caller's own: one they made, or one a run that acts for them made.

## `client.files.versions.add()`

```python signature
add(
    file_id: str | UUID,
    files: Mapping[str, Any],
    /,
    *,
    idempotency_key: str | None = None,
    data: Mapping[str, Any] | None = None,
    timeout: float | None = None,
) -> FileVersionWrite
```

Add a version. `POST /v1/files/{fileId}/versions`

Multipart upload of a file's next version, which becomes Latest. The `file` part carries the bytes; the other form fields are `name` (a new name for the file), `contentType`, `tags` (JSON), `expectedVersion` and `expectedHash`. With `expectedVersion`, a Latest that isn't it is `409 file-version-conflict`, and nothing is written; without it, the last write wins, and the version in between stays in the history. Bytes that are already Latest's add no version (`200`, `created: false`); bytes an earlier version has are kept once. Needs `write` on the file's project, even for a file of the caller's own. Over the runtime's cap is `413 file-too-large`. A version the workspace's storage limit has no room for is `403 storage-limit-reached`, and nothing is stored.

## `client.files.versions.get()`

```python signature
get(
    file_id: str | UUID,
    version: str,
    /,
    *,
    timeout: float | None = None,
) -> FileVersion
```

Get a version. `GET /v1/files/{fileId}/versions/{version}`

One version's record, without its bytes: a deleted or purged one too. `latest` names Latest. Needs `read` on the file's project, or `run` there for a file of the caller's own: one they made, or one a run that acts for them made.

## `client.files.versions.delete()`

```python signature
delete(
    file_id: str | UUID,
    version: int,
    /,
    *,
    idempotency_key: str | None = None,
    timeout: float | None = None,
) -> DeleteFileResult
```

Delete a version. `DELETE /v1/files/{fileId}/versions/{version}`

Deletes one version: a soft delete, kept until a retention policy for `file_version` purges it. Its number is never reused. Deleting Latest moves Latest to the next live version down. Idempotent: `{ deleted: true }` the first time, `{ deleted: false }` after. Needs `write` on the file's project.

## `client.files.versions.download()`

```python signature
download(file_id: str | UUID, version: str, /, *, timeout: float | None = None) -> bytes
```

Download a version's bytes (stream). `GET /v1/files/{fileId}/versions/{version}/content`

Streams one version's raw bytes, as a download. `latest` names Latest. A deleted or purged version is `404 file-version-not-found`: a fixed version never falls back to Latest. Response headers: `Content-Type` (as declared when it is a well-formed media type of at most 255 characters, else `application/octet-stream`), `Content-Disposition` (`attachment`, with the name), `X-Content-Type-Options: nosniff`, `Content-Security-Policy` (`default-src 'none'; sandbox`), `Content-Length`, `X-Kindgi-Blob-Hash` (sha256 hex), `X-Kindgi-Blob-Name` (URI-encoded name), and `X-Kindgi-File-Version` (the number served). Needs `read` on the file's project, or `run` there for a file of the caller's own: one they made, or one a run that acts for them made.

## `client.files.versions.restore()`

```python signature
restore(
    file_id: str | UUID,
    version: int,
    body: RestoreFileVersionBody | Mapping[str, Any] | None = None,
    /,
    *,
    idempotency_key: str | None = None,
    timeout: float | None = None,
    **fields: Any,
) -> FileVersionWrite
```

Restore a version. `POST /v1/files/{fileId}/versions/{version}/restore`

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.

## `client.files.versions.pin()`

```python signature
pin(
    file_id: str | UUID,
    version: int,
    body: PinFileVersionBody | Mapping[str, Any] | None = None,
    /,
    *,
    idempotency_key: str | None = None,
    timeout: float | None = None,
    **fields: Any,
) -> FileVersion
```

Pin a version. `POST /v1/files/{fileId}/versions/{version}/pin`

A keep mark on one version, with who and why: it can't be deleted, and retention never purges it. A pin never moves Latest, and doesn't change what a run gets. Pinning a pinned version changes nothing, and a deleted or purged one is `404 file-version-not-found`. Each pin is kept in the file's pin history. Needs `write` on the file's project.

## `client.files.versions.unpin()`

```python signature
unpin(
    file_id: str | UUID,
    version: int,
    body: PinFileVersionBody | Mapping[str, Any] | None = None,
    /,
    *,
    idempotency_key: str | None = None,
    timeout: float | None = None,
    **fields: Any,
) -> FileVersion
```

Unpin a version. `POST /v1/files/{fileId}/versions/{version}/unpin`

Takes a version's pin off, kept in the file's pin history with who and why. Unpinning a version with no pin changes nothing. Needs `write` on the file's project.
