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

# Files

> Upload files, attach them to sessions, and browse or download session files.

The files endpoints support two main workflows:

1. **Make existing files available to a session**: Upload a file, save the returned `file_id`, and attach it either when creating a session or while a session is running.
2. **Retrieve session files**: List the files in a session, then download the ones you need.

Uploaded files are not automatically attached to sessions.
Manage uploaded files through `/v1/files`, and browse or download session files through `/v1/sessions/{session_id}/filesystem`.

> [!WARNING]
>
> The response format of `/v1/files*` endpoints is controlled by the `kimi-api-version` request header: sending `2026-09-01-beta` returns the Hosted Agents format (HTTP `201` on upload, HTTP `204` on deletion, and the `FileMetadata` response model); omitting the header returns the Kimi API Platform legacy-compatible format (HTTP `200` on upload, HTTP `200` on deletion, and the `FileObject` model); any other non-empty value returns HTTP `400`. Status codes and field names differ between the two formats, so each client should stick to one format and never mix parsing logic. We recommend including `kimi-api-version: 2026-09-01-beta` on every request: it keeps the response format consistent, and only files with `file_`-prefixed IDs created under this format can be attached to sessions.

## Upload files and attach them to a session

In enterprise organizations, open **Files** under **Project** in the console sidebar, select the **Hosted Agents** tab, and click **Upload file** to upload a local file; see [Using the Console](https://platform.kimi.ai/docs/hosted-agents/console.md#files) for details. You can also upload files with the REST API (`POST /v1/files`) or the [kha CLI](https://platform.kimi.ai/docs/hosted-agents/kha.md), then select them in the **Files** field when creating a session in the console. To inspect files delivered by agents, open **Artifacts** under **Project** in the console sidebar. The examples below show both cURL and `kha` CLI commands.

### Upload a file

Send a `multipart/form-data` request to `POST /v1/files`.
The `file` part is required; the filename can come from the `file` part itself or be specified via the `filename` form field.
`purpose` specifies how the file is processed: `file-extract`, `image`, `video`, or `batch`. Only the uploader can read the content of or delete a file uploaded with `purpose=batch`, and such files cannot be attached to a session.
Each file can be at most 100 MiB and cannot be updated after upload.
The default total storage quota per organization is 10 GiB. Once the quota is reached, new uploads are rejected; delete unused files to free up quota.

Include the `kimi-api-version: 2026-09-01-beta` request header when calling `/v1/files*` endpoints to use the current API version.
The command below saves `id` from the upload response to `FILE_ID` for use in subsequent requests.

```bash cURL theme={null}
UPLOAD_RESPONSE=$(curl --request POST "https://api.moonshot.ai/v1/files" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta" \
  --form "file=@report.pdf" \
  --form "purpose=file-extract")
FILE_ID=$(printf '%s' "$UPLOAD_RESPONSE" | jq -r '.id')
```

```bash CLI theme={null}
FILE_ID=$(kha files upload --file report.pdf --purpose file-extract -o json | jq -r '.id')
```

On success, the endpoint responds with HTTP `201` and a file object.
`FILE_ID` comes from `id` in the upload response and can be used to attach the file, retrieve its metadata, read its content, or delete it.

```json theme={null}
{
  "id": "$FILE_ID",
  "filename": "report.pdf",
  "mime_type": "application/pdf",
  "size_bytes": 204800,
  "created_at": "2026-08-26T12:00:00Z",
  "purpose": "file-extract",
  "extract_status": "ready"
}
```

`extract_status` indicates the parsing status of the file: `ready` means the file is ready for use, and `error` means parsing failed.
A file whose parsing failed can still be attached to a session, but the session receives only the raw file without extracted text.

When a file with the same name is uploaded within the same scope, the server appends a suffix to the filename to avoid collisions.

### Attach a file when creating a session

When creating a session, add a session resource object with `type` set to `file` in the `resources` array of the request body, using the `FILE_ID` saved in the previous step.
For a complete session creation request example, see [Create a Session](https://platform.kimi.ai/docs/hosted-agents/sessions.md).

```json theme={null}
{
  "resources": [
    {
      "type": "file",
      "file_id": "$FILE_ID"
    }
  ]
}
```

### Add a file during a running session

After creating a session, you can add file resources via `POST /v1/sessions/{session_id}/resources`.
`SESSION_ID` comes from `id` in the session creation response; see [Create a Session](https://platform.kimi.ai/docs/hosted-agents/sessions.md).
Only file resources can be added after session creation—vaults, memory stores, and [GitHub repositories](https://platform.kimi.ai/docs/hosted-agents/github.md) must be attached when creating the session.

```bash cURL theme={null}
curl --request POST "https://api.moonshot.ai/v1/sessions/$SESSION_ID/resources" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta" \
  --header "Content-Type: application/json" \
  --data '{
    "type": "file",
    "file_id": "'"$FILE_ID"'"
  }'
```

```bash CLI theme={null}
kha sessions resources add "$SESSION_ID" --file-id "$FILE_ID"
```

On success, the endpoint responds with HTTP `201` and a session resource object whose `id` identifies this resource binding.

> [!NOTE]
>
> Only file IDs with the `file_` prefix can be attached to a session. Legacy IDs synced from the previous Kimi API Platform (without the `file_` prefix) cannot be attached and return an error when submitted.

### Manage uploaded files

The scope of `GET /v1/files` depends on the version header: sending `2026-09-01-beta` lists files in the current project, whereas omitting the version header lists files across the entire organization.
Results are returned in reverse chronological order by upload time, with the most recently uploaded files first. Both formats support pagination via `page_size` (1–1000) and `page_token`, returning the full list when those parameters are omitted; the Hosted Agents format uses `next_page_token` in the response to fetch the next page (omitted when there are no further pages), while the Model Inference API-compatible format uses `has_more` to indicate whether another page exists.
To check which uploaded files are attached to a given session, call `GET /v1/sessions/{session_id}/filesystem?prefix=upload/` to list the files under `upload/` in that session.

Retrieve metadata for `FILE_ID`:

```bash cURL theme={null}
curl --request GET "https://api.moonshot.ai/v1/files/$FILE_ID" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
kha files get "$FILE_ID"
```

Read the content of `FILE_ID`.
What the endpoint returns depends on `purpose`: for a `file-extract` file, it returns a JSON object with the extracted Markdown in the `content` field; for a `batch` file, it returns the uploaded file content, which is parsed and normalized on upload so the returned bytes may differ from the original upload.
`image` files, `video` files, and files that failed parsing have no extracted content, so requesting their content returns HTTP `400` (`failed_precondition_error`).

The command below reads the content of `FILE_ID` and uses `jq` to write the Markdown in `content` to `report.md`:

```bash cURL theme={null}
curl --request GET "https://api.moonshot.ai/v1/files/$FILE_ID/content" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta" | jq -r '.content' > report.md
```

```bash CLI theme={null}
kha files download "$FILE_ID" --out report.md
```

Delete the uploaded file `FILE_ID` (responds with HTTP `204` on success):

```bash cURL theme={null}
curl --request DELETE "https://api.moonshot.ai/v1/files/$FILE_ID" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
kha files delete "$FILE_ID"
```

`FILE_ID` in all of these commands comes from the upload response.

## Response format comparison

Both `/v1/files*` response formats are served side by side: omitting `kimi-api-version` returns the Model Inference API-compatible format, while sending `2026-09-01-beta` returns the Hosted Agents format. Files synced from the legacy Kimi API Platform and newly uploaded files appear in the same list.

| Aspect | Model Inference API-compatible format | Hosted Agents format |
| - | - | - |
| Trigger | Omit `kimi-api-version` request header | `kimi-api-version: 2026-09-01-beta` |
| List scope | Entire organization | Caller's project |
| List response structure | `{object, data, first_id, last_id, has_more}` | `{items, next_page_token}` |
| File model | `FileObject` | `FileMetadata` |
| Upload status code | `200` | `201` |
| Delete status code | `200` | `204` |
| Pagination | `page_size` / `page_token`; returns full list when omitted; `has_more` indicates whether more pages exist | Same parameters; uses `next_page_token` to fetch the next page |
| Session-attachable IDs | Only `file_`-prefixed IDs | Only `file_`-prefixed IDs |

Field mapping between the two file models:

| Model Inference API (`FileObject`) | Hosted Agents (`FileMetadata`) | Description |
| - | - | - |
| `id` | `id` | File ID; legacy synced IDs and `file_`-prefixed IDs coexist |
| `object` (always `file`) | — | Not present in Hosted Agents format |
| `bytes` | `size_bytes` | File size in bytes |
| `created_at` (Unix seconds) | `created_at` (RFC 3339) | Different timestamp representations; handle accordingly when parsing |
| `filename` | `filename` | Filename; numeric suffix appended automatically on collision within a project |
| `file_type` | `mime_type` | MIME type |
| `purpose` | `purpose` | Purpose (`file-extract` / `image` / `video` / `batch`) |
| `status` (`ready` / `error`) | `extract_status` (`ready` / `error`) | Parsing status |
| `status_details` | — | Failure details; not exposed in Hosted Agents format |

## Retrieve session files

In the console, open the session details page and select the **Files** panel on the right to browse the session working directory tree level by level; files generated by the agent are saved in the `output` directory. Files delivered by the agent also appear on the project's **Artifacts** page. See [Using the Console](https://platform.kimi.ai/docs/hosted-agents/console.md#session-workspace) for details.

### List session files

Files generated or saved while a session runs are stored under the session and listed via `GET /v1/sessions/{session_id}/filesystem`.
The endpoint returns one directory level at a time: omitting `prefix` lists the root directory, and passing a directory prefix lists the direct files and subdirectories under that path.

```bash cURL theme={null}
curl --request GET "https://api.moonshot.ai/v1/sessions/$SESSION_ID/filesystem?prefix=output" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
kha sessions fs list "$SESSION_ID" --prefix output
```

Listing session files returns `SessionFSNode` entries:

| Field | Type | Description |
| - | - | - |
| `name` | `string` | File or directory name, such as `report.txt` or `output` |
| `path` | `string` | Path relative to the session filesystem root; pass this value when downloading |
| `is_dir` | `boolean` | Whether the entry is a directory |
| `size_bytes` | `integer` | File size in bytes (`0` for directories) |
| `last_modified` | `string` | Last modified timestamp (optional) |

> [!NOTE]
>
> The response returns all direct children of the requested directory in a single call without pagination.
> Uploaded files attached to a session are located under `upload/`; pass `prefix=upload/` to list them.

### Download a session file

Pass the `path` of a listed entry to `GET /v1/sessions/{session_id}/filesystem/raw` to download the file.

```bash cURL theme={null}
curl --request GET "https://api.moonshot.ai/v1/sessions/$SESSION_ID/filesystem/raw?path=output/report.pptx" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta" \
  --output report.pptx
```

```bash CLI theme={null}
kha sessions fs download "$SESSION_ID" output/report.pptx --out report.pptx
```

Session files are not guaranteed to be fully durable: files written by background processes that keep running after the agent finishes may be lost or incomplete, and directory listings may lag behind recent writes. When you need durable, versioned outputs, have the agent deliver them as artifacts via `save_artifact`—artifacts are managed through dedicated artifact endpoints.

## Next steps

> [card] [Attach files and retrieve artifacts](https://platform.kimi.ai/docs/hosted-agents/sessions.md)
>
> Learn about the session lifecycle, session creation, and sending and receiving messages.
