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

# Scripting and Automation

> Script the ade CLI with stable JSON output, pipeable IDs, and exit codes, and run it unattended in CI and cron.

Every ade CLI command prints a result a script can parse, returns an exit code that says what to do next, and is safe to re-run. So you can:

* Pipe IDs and results straight into other tools (`--id-only`, `--json`).
* Submit long jobs now and collect them later (`--wait 0`).
* Batch whole folders, and re-run after a crash: finished work is served from disk.

## Capture an ID for Piping

The `--id-only` flag prints just the job item ID, one per line. Errors go to stderr, so a captured ID is never an error sentence:

```bash Command theme={null}
ade parse -d patient-statement-brackenmill.pdf --id-only
```

```text Output theme={null}
bee989875c369fc5
```

Assign it directly in a script, then feed it to any command that takes an ID:

```bash theme={null}
JOB=$(ade parse -d patient-statement-brackenmill.pdf --id-only)
ade extract "$JOB" --schema schema-patient-statement.json --json
```

## Pipe Results to Other Tools

With `--json`, the whole result is on stdout as one object or array, so a script never reads files out of the store. Failures and unfinished jobs use the same shape, so one parser handles every outcome.

The large artifacts stay on disk unless you carry them along with `--include`. Here the parse markdown flows straight into another tool:

```bash Command theme={null}
ade parse -d patient-statement-brackenmill.pdf --json --include markdown | jq -r .markdown | head -4
```

```text Output theme={null}
[Pulse symbol inside rounded square]


Brackenmill Family Health
```

## Branch on Exit Codes

Exit codes separate "wrong" from "not yet." Codes `3` (wait expired, job still running) and `4` (rate-limited, nothing consumed) both mean the same recovery: run the same command again. The [CLI Reference](./reference) lists every code.

```bash theme={null}
ade parse -d "$FILE" --json
case $? in
  0) echo "done" ;;
  3|4) echo "not finished; re-run this script to resume" ;;
  *) echo "failed" >&2; exit 1 ;;
esac
```

## Submit Now, Collect Later

Pass `--wait 0` to submit a job and return immediately with exit code `3`. Collect the result whenever you like by re-running the same command: it reconnects to the recorded job and never consumes credits twice.

```bash theme={null}
ade parse -d big-document.pdf --wait 0 --id-only
ade parse -d big-document.pdf --json
```

## Process a Folder of Documents

Free re-runs make batch jobs resumable. If this loop dies halfway, run it again, and only the unfinished documents do real work.

```bash theme={null}
for f in *.pdf; do
  ade parse -d "$f" --id-only
done
```

## Run Unattended

In an unattended environment, such as a continuous integration (CI) pipeline, a cron job, or an AI agent harness, set the `ADE_API_KEY` environment variable for credentials. [Authentication](./authentication) covers the options.

Non-interactive shells source no profile, so the `ade` command your login shell finds may not be on the job's PATH. Call the binary by its absolute path, or add it to PATH inside the job:

```bash theme={null}
export PATH="$HOME/.ade/bin:$PATH"
ade parse -d "$FILE" --json
```

## Next Steps

<CardGroup cols={2}>
  <Card title="CLI Reference" icon="book" href="./reference">
    Every command, flag, and payload key these patterns build on.
  </Card>

  <Card title="CLI Concepts" icon="terminal" href="./concepts">
    Why re-runs are free: job items, guarantees, and the local store.
  </Card>
</CardGroup>
