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

> ## Agent Instructions
> Checkfu is open source (https://github.com/checkfu/checkfu) and runs in the reader's own Cloudflare account. There is no shared hosted base URL: `checkfu deploy` prints the deployment's API URL (`https://<api-worker>.workers.dev` or the CHECKFU_API_DOMAIN hostname, exported as `CHECKFU_BASE_URL` for the CLI, SDK, and curl) and MCP URL (`.../mcp`). Local development serves the API on http://localhost:1337 and MCP on http://localhost:1338/mcp.
> Authenticated HTTP requests send the deployment's CHECKFU_API_KEY as `Authorization: Bearer $CHECKFU_API_KEY` (or `x-api-key`) and `Content-Type: application/json` for JSON bodies. Pass `Idempotency-Key` on retriable writes.
> Core workflow: create an Agent (`POST /v1/agents`) and an Environment (`POST /v1/environments`), create a Session that references both (`POST /v1/sessions`), send a `user.message` event (`POST /v1/sessions/{session_id}/events`), and follow `GET /v1/sessions/{session_id}/events/stream` until `session.status_idle`.
> Other resources: Memory stores (`/v1/memory_stores`), Files (`/v1/files`), Artifacts (`/v1/artifacts`), Vaults and credentials (`/v1/vaults`), Provider credentials (`/v1/provider_credentials`), Automations (`/v1/automations`), Inbound bindings (`/v1/inbound_bindings`), and Webhooks (`/v1/webhooks`). The deployment serves its OpenAPI 3.1 specification at `GET /openapi.json`.

# Files

> Upload bytes for agents to read, and download the files Sessions produce.

A File is an immutable upload or session output. Retrieve its filename, `mime_type`, `size_bytes`, and SHA-256 digest with `files.retrieve(fileId)`.

Both examples upload `report.pdf` and save a separate copy to `downloaded-report.pdf`.

```sh CLI theme={"theme":{"light":"github-light","dark":"github-dark"}}
FILE_ID=$(checkfu --transform id -r files upload ./report.pdf) &&
  checkfu files download --file-id "$FILE_ID" -o ./downloaded-report.pdf
```

```sh curl theme={"theme":{"light":"github-light","dark":"github-dark"}}
(
  set -eu
  download=./downloaded-report.pdf
  if [ -e "$download" ] || [ -L "$download" ]; then
    printf 'The download destination already exists.\n' >&2
    exit 1
  fi

  temporary=$(mktemp ./.downloaded-report.XXXXXX)
  trap 'rm -f "$temporary"' EXIT
  trap 'exit 1' HUP INT TERM

  status=$(curl --disable --fail --silent --show-error \
    --output "$temporary" --write-out '%{http_code}' \
    "$CHECKFU_BASE_URL/v1/files?filename=report.pdf" \
    -H "Authorization: Bearer $CHECKFU_API_KEY" \
    -H "Content-Type: application/pdf" \
    --data-binary @report.pdf)
  if [ "$status" != 201 ]; then
    printf 'Upload returned HTTP %s.\n' "$status" >&2
    exit 1
  fi
  FILE_ID=$(jq -er '.id | select(type == "string" and length > 0)' "$temporary")

  status=$(curl --disable --fail --silent --show-error \
    --output "$temporary" --write-out '%{http_code}' \
    "$CHECKFU_BASE_URL/v1/files/$FILE_ID/content" \
    -H "Authorization: Bearer $CHECKFU_API_KEY")
  if [ "$status" != 200 ]; then
    printf 'Download returned HTTP %s.\n' "$status" >&2
    exit 1
  fi
  link "$temporary" "$download"
)
```

The API accepts a raw octet stream up to 100 MiB or a multipart request with one `file` part up to 16 MiB. To retry an upload safely, reuse the idempotency key with the same filename, media type, and bytes.

The CLI prints a generated `Idempotency-Key` to stderr before uploading. If the upload's outcome is uncertain, rerun the command with `--idempotency-key` set to that value and keep the original file and options.

The HTTP example saves the completed download after curl succeeds. A failed transfer removes its temporary file. Choose an unused filename for each download.

## Transfer bytes with the SDK

```ts theme={"theme":{"light":"github-light","dark":"github-dark"}}
import Checkfu from "@checkfu/sdk"
import { readFile, writeFile } from "node:fs/promises"

const client = new Checkfu()
try {
	const file = await client.files.upload({
		filename: "report.pdf",
		content_type: "application/pdf",
		body: await readFile("report.pdf"),
	})
	await writeFile("downloaded-report.pdf", await client.files.download(file.id), { flag: "wx" })
} finally {
	await client.close()
}
```

The download endpoint sends an ETag based on the content digest. A matching `If-None-Match` returns HTTP 304 with an empty body. Use `Range` for partial downloads and `If-Range` to receive the full file when the validator is stale. The SDK returns the bytes and can expose the HTTP status and headers.

The signed-in dashboard downloads saved Files from the Files panel of the session that captured them.

## Attach a File to a Session

Pass a `file` resource when you create the Session:

```ts theme={"theme":{"light":"github-light","dark":"github-dark"}}
import Checkfu, { FileId } from "@checkfu/sdk"

const client = new Checkfu()

const session = await client.waitForPending(
	await client.sessions.create({
		agent: agent.id,
		environment_id: environment.id,
		resources: [{ type: "file", file_id: FileId.make(file.id), mount_path: "/q3/report.pdf" }],
	}),
)
```

The agent reads it at `/mnt/session/uploads/q3/report.pdf`. A leading slash starts at the uploads directory. `q3/report.pdf` resolves to the same file path. Omit `mount_path` to use the filename, or pass `null` to use the file ID.

The agent's file tools can read uploads directly. To pass an upload to `bash`, the agent first copies it into `/workspace`.

To reuse a saved File in the dashboard, choose **Use in new session** in the source session's Files panel. Review the read-only mount and start the new session when you are ready. The new session references the same File.

## Files from Session outputs

When a turn ends with `end_turn`, `budget_reached`, or `refusal`, Checkfu captures `/mnt/session/outputs` after the Session goes idle, subject to [Session output limits](https://docs.checkfu.com/reference/limits.md#session-outputs). Other stop reasons produce no capture. The latest output record includes the turn and status of the most recent capture attempt.

```ts theme={"theme":{"light":"github-light","dark":"github-dark"}}
const wantedTurn = 4
const outputs = await client.sessions.outputs.retrieve(session.id)
if (outputs.turn === wantedTurn && outputs.status === "saved") {
	for (const file of outputs.files) console.log(file.id, file.filename)
} else if (outputs.turn === wantedTurn && outputs.status === "skipped") {
	console.log("Capture skipped", outputs.reason)
}
```

* A lower `outputs.turn` means the latest capture attempt precedes the turn you want. Check the turn's stop reason before waiting for a capture.
* A matching turn with status `saved` lists the currently available Files from that turn's capture. Unchanged files can retain their IDs. The `skipped` array lists individual paths omitted during the capture.
* A matching turn with status `skipped` has a `reason` for the whole capture. Its File list shows the currently available Files from the last successful capture.
* A higher `outputs.turn` means the latest record has advanced. Use the Session's output history to find the earlier capture.

Call `client.sessions.outputs.history(session.id, { order: "desc" })` to list captures from newest to oldest. Follow `next_page` until you find the requested `turn` or reach the end. A skipped history entry has a `reason` and an empty File list. The latest record and history both omit Files deleted after capture.

To refresh when an outcome is recorded, subscribe a [Webhook](https://docs.checkfu.com/concepts/webhooks.md) to `session.outputs_recorded`.

For results too large to save as session outputs, have the agent save an [Artifact](https://docs.checkfu.com/concepts/artifacts.md) with `save_artifact`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.