# Write a mount file

Create or replace one file of a mount, creating any missing parent folders.

`PUT https://api.smallworld.sh/api/v1/mounts/:mountId/files/content`

## Parameters

| Name | Location | Type | Required | Description |
| --- | --- | --- | --- | --- |
| mountId | path | UUID | Yes | The mount's ID, returned as id when the mount was created. |
| path | query | string | Yes | A path inside the mount, such as /guides/refunds.md for /workspace/docs/guides/refunds.md in a mount at /workspace/docs. guides/refunds.md names the same file. No empty, . or .. segments and no trailing slash. URL-encode it. |
| content | body | string | Yes | The file's content: text for utf8, or base64 for any bytes. |
| encoding | body | string | No | utf8 (the default) or base64. |

## Request examples

### curl

```curl
curl --fail-with-body -X PUT 'https://api.smallworld.sh/api/v1/mounts/0199a1c4-5b6e-7a10-9c2d-3e4f5a6b7c8d/files/content?path=/faq.md' \
  -H "Authorization: Bearer $SMALLWORLD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "content": "# FAQ\n\nRefunds take 3 business days.\n"
}'
```

### typescript

```typescript
const response = await fetch("https://api.smallworld.sh/api/v1/mounts/0199a1c4-5b6e-7a10-9c2d-3e4f5a6b7c8d/files/content?path=/faq.md", {
  method: "PUT",
  headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
  body: JSON.stringify({
  "content": "# FAQ\n\nRefunds take 3 business days.\n"
}),
});
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
const result = await response.json();
```

### python

```python
response = requests.put(
    "https://api.smallworld.sh/api/v1/mounts/0199a1c4-5b6e-7a10-9c2d-3e4f5a6b7c8d/files/content?path=/faq.md",
    headers={"Authorization": f"Bearer {api_key}"},
    json={
  "content": "# FAQ\n\nRefunds take 3 business days.\n"
},
    timeout=30,
)
response.raise_for_status()
result = response.json()
```

## Responses

Returns status (created, updated, or unchanged) and entry, the file as GET /mounts/:mountId/files lists it. unchanged means the file already had exactly this content, and nothing was written.

### 200 · Updated

The file existed with other content and was replaced.

```json
{
  "status": "updated",
  "entry": {
    "path": "/faq.md",
    "type": "file",
    "size": 37,
    "hash": "e08222b5163270229c47f385e4d0e8a9de482f71d0364a66de787c09b3b63b0a",
    "modifiedAt": "2026-10-10T12:00:01.000Z"
  }
}
```

### 200 · Created

The file didn't exist. It was created, with any missing parent folders.

```json
{
  "status": "created",
  "entry": {
    "path": "/faq.md",
    "type": "file",
    "size": 37,
    "hash": "e08222b5163270229c47f385e4d0e8a9de482f71d0364a66de787c09b3b63b0a",
    "modifiedAt": "2026-10-10T12:00:01.000Z"
  }
}
```

### 200 · Unchanged

The file already had exactly this content. Nothing was written and the change log has no entry.

```json
{
  "status": "unchanged",
  "entry": {
    "path": "/faq.md",
    "type": "file",
    "size": 37,
    "hash": "e08222b5163270229c47f385e4d0e8a9de482f71d0364a66de787c09b3b63b0a",
    "modifiedAt": "2026-10-10T12:00:00.000Z"
  }
}
```

### 400

invalid_request: The path query parameter is missing, content isn't a string, encoding isn't utf8 or base64, content isn't valid base64, or the request has an unknown field or query parameter. The message names the problem. mount_invalid_path: The path query parameter isn't a canonical path inside the mount: it is / itself, ends with a slash, has empty, . or .. segments, contains null bytes, backslashes, or control characters, or is too long.

#### invalid_request

The path query parameter is missing, content isn't a string, encoding isn't utf8 or base64, content isn't valid base64, or the request has an unknown field or query parameter. The message names the problem.

```json
{
  "statusCode": 400,
  "code": "invalid_request",
  "message": "Unknown field: color"
}
```

#### mount_invalid_path

The path query parameter isn't a canonical path inside the mount: it is / itself, ends with a slash, has empty, . or .. segments, contains null bytes, backslashes, or control characters, or is too long.

```json
{
  "statusCode": 400,
  "code": "mount_invalid_path",
  "message": "path must be a canonical path, without empty, . or .. segments or a trailing slash"
}
```

### 401

authentication_required: The Authorization header is missing or empty. invalid_api_key: The API key is invalid or revoked, or the header doesn't use the Bearer scheme.

#### authentication_required

The Authorization header is missing or empty.

```json
{
  "statusCode": 401,
  "code": "authentication_required",
  "message": "Authentication is required"
}
```

#### invalid_api_key

The API key is invalid or revoked, or the header doesn't use the Bearer scheme.

```json
{
  "statusCode": 401,
  "code": "invalid_api_key",
  "message": "The API key is invalid or revoked"
}
```

### 403

ip_not_allowed: The request came from an address outside the workspace's IP allowlist.

#### ip_not_allowed

The request came from an address outside the workspace's IP allowlist.

```json
{
  "statusCode": 403,
  "code": "ip_not_allowed",
  "message": "The source IP address is not allowed by this account's security settings"
}
```

### 404

mount_not_found: The mount does not exist in your workspace, or mountId isn't a mount ID.

#### mount_not_found

The mount does not exist in your workspace, or mountId isn't a mount ID.

```json
{
  "statusCode": 404,
  "code": "mount_not_found",
  "message": "Mount not found"
}
```

### 409

mount_file_conflict: The path is a folder, or one of its parents is a file. The message names the paths as the terminal sees them; nothing is written.

#### mount_file_conflict

The path is a folder, or one of its parents is a file. The message names the paths as the terminal sees them; nothing is written.

```json
{
  "statusCode": 409,
  "code": "mount_file_conflict",
  "message": "/workspace/docs/guides is a folder"
}
```

### 413

mount_limit: The file is larger than 64 MiB, or the mount would hold more than 64 MiB or 10,000 files and folders. Nothing is written. request_too_large: The JSON body is larger than 12 MiB. File uploads count toward it, base64 or escaping included.

#### mount_limit

The file is larger than 64 MiB, or the mount would hold more than 64 MiB or 10,000 files and folders. Nothing is written.

```json
{
  "statusCode": 413,
  "code": "mount_limit",
  "message": "The mount would exceed 64 MiB"
}
```

#### request_too_large

The JSON body is larger than 12 MiB. File uploads count toward it, base64 or escaping included.

```json
{
  "statusCode": 413,
  "code": "request_too_large",
  "message": "The request body is larger than 12 MiB."
}
```

### 415

unsupported_media_type: The request has a body that isn't JSON. Send JSON with Content-Type: application/json, or no body at all.

#### unsupported_media_type

The request has a body that isn't JSON. Send JSON with Content-Type: application/json, or no body at all.

```json
{
  "statusCode": 415,
  "code": "unsupported_media_type",
  "message": "Send the request body as JSON with Content-Type: application/json."
}
```

### 500

internal_error: An unexpected server error.

#### internal_error

An unexpected server error.

```json
{
  "statusCode": 500,
  "code": "internal_error",
  "message": "Internal server error"
}
```

## Notes

- This write is direct: it skips the mount's settings, tool call hooks, and approvals, and takes effect at once. It appears in the mount's change log in the dashboard. It always overwrites, without a version check.

- A command that first saw this file before your write and changes it, also one waiting for approval, has its changes to the mount discarded, with a notice in stderr. Commands that change other files of the mount are unaffected.

- A file can be at most 64 MiB, and the mount at most 64 MiB and 10,000 files and folders. A JSON request body is at most 12 MiB, base64 included.
