# fs_upload_begin

Begin a resumable create-only upload, up to 256 MiB. Bind a client-generated id, size and SHA-256; expires in 15 minutes. Use SDK upload helpers for bytes.

**In short:** Risk class [`write`](https://docs.cmdop.ai/reference/tools.md#risk-classes). Over MCP call `fs_upload_begin`; over HTTP send `"tool": "fs_upload_begin"` to [`POST /api/v1/call`](https://docs.cmdop.ai/reference/http/post-call.md).

## Arguments

Over MCP every tool also takes `machine`: the machine's name or id, optional when only one machine is online.

| Name | Type | Required | Meaning |
| --- | --- | --- | --- |
| `mkdirs` | `boolean` | no | Create missing parent folders. Default: false. Default: `false`. |
| `path` | `string` | yes | Destination on the machine. Existing files are never replaced. |
| `sha256` | `string` | yes | Expected whole-file SHA-256: 64 lowercase hexadecimal characters. |
| `size` | `integer` | yes | Exact decoded byte count, at most 268435456 (256 MiB). |
| `transfer` | `string` | yes | Client-generated id: 32 lowercase hexadecimal characters. Reuse only for this upload. |

## Result

| Name | Type | Required | Meaning |
| --- | --- | --- | --- |
| `chunk_max_bytes` | `integer` | yes | Maximum decoded bytes in a chunk. |
| `expires_at` | `integer` | yes | Fixed expiry as Unix seconds. |
| `offset` | `integer` | yes | Durable confirmed byte offset. Only continue from this value. |
| `path` | `string` | yes | Bound canonical absolute destination. |
| `receipt` | `object` | no | Present only after verified publication. |
| `sha256` | `string` | yes | Expected whole-file SHA-256; a committed receipt confirms verification. |
| `size` | `integer` | yes | Expected whole-file decoded bytes. |
| `state` | `"uploading" \| "committed" \| "aborted" \| "expired"` | yes | Current durable state. |
| `transfer` | `string` | yes | Client-generated upload id. |

## Examples

**MCP**

```json
{
  "name": "fs_upload_begin",
  "arguments": {
    "machine": "<machine>",
    "transfer": "<transfer>",
    "path": "<path>",
    "size": 0,
    "sha256": "<sha256>"
  }
}
```

**HTTP**

```bash
curl -sS -X POST "https://<contour>.cmdop.dev/api/v1/call" \
  -H "Authorization: Bearer $CMDOP_TOKEN" \
  -H "x-cmdop: 1" \
  -H "Content-Type: application/json" \
  -d '{"machine":"<machine>","tool":"fs_upload_begin","args":{"transfer":"<transfer>","path":"<path>","size":0,"sha256":"<sha256>"}}'
```

## Limits

The call times out after 60 s (`timed_out`). Available since version 0.1.18. A refused or failed call returns one of the [error codes](https://docs.cmdop.ai/reference/errors.md).

## Notes

Generate the transfer identifier in code and save it before the first call. Reuse it only
for the same source bytes, destination and authenticated client. The identifier alone does
not grant access. Every upload operation still requires the current `write` grant and the
machine's ceiling.

A machine accepts at most four active uploads and reserves at most 512 MiB of their declared
sizes in total. The 15-minute expiry starts at begin and does not move when chunks arrive.
Keep the identifier after an uncertain reply and inspect
[fs_upload_status](https://docs.cmdop.ai/reference/tools/fs_upload_status.md) before continuing.

For local files, use the [SDK upload helpers](https://docs.cmdop.ai/reference/sdk/files-and-screen.md#upload-a-local-file)
to compute hashes and send bounded chunks in code. Access to the source file must already
exist in that runtime; a ChatGPT file reference is not a local source path.
