# l4 export

> Bulk-export costs and recommendations to CSV or JSON for spreadsheets, BI tools, or archival.

Source: https://docs.levelfour.ai/cli/commands/export


`l4 export` handles the pagination internally and emits a single, well-formed CSV. Use it when the destination is a spreadsheet, a BI tool, or a backup.

## Subcommands

| Command                               | Purpose                              |
| ------------------------------------- | ------------------------------------ |
| [`costs`](#costs)                     | Export cost data over a time period  |
| [`recommendations`](#recommendations) | Export the full recommendations list |
| [`commitments`](#commitments)         | Export the commitment ledger         |

> **Note**
>
> `l4 costs --csv` and `l4 recommendations list --csv` are intentionally not supported. Those commands are paginated, and the per-page envelopes do not compose cleanly into a single CSV. [Output formats](/cli/output-formats#--csv) has what `--csv` does on every other command.

## costs

```bash
l4 export costs [flags]
```

| Flag            | Description                             |
| --------------- | --------------------------------------- |
| `--period <p>`  | Time period: `7d`, `30d`, `90d`, `365d` |
| `--account <a>` | Filter by account                       |
| `--format <f>`  | `csv` (default) or `json`               |
| `--out <path>`  | Write to file instead of stdout         |

```bash
l4 export costs --format csv --period 90d > costs.csv
l4 export costs --format json --period 30d --out costs.json
l4 export costs --period 30d --account "123456789012 (prod)" > prod-costs.csv
```

## recommendations

```bash
l4 export recommendations [flags]
```

| Flag            | Description                     |
| --------------- | ------------------------------- |
| `--account <a>` | Filter by account               |
| `--format <f>`  | `csv` (default) or `json`       |
| `--out <path>`  | Write to file instead of stdout |

```bash
l4 export recommendations --format csv > recommendations.csv
l4 export recommendations --format json --out recs.json
```

## commitments

```bash
l4 export commitments [flags]
```

| Flag              | Description                          |
| ----------------- | ------------------------------------ |
| `--provider <id>` | `aws` or `gcp` (resolved if omitted) |
| `--format <f>`    | `csv` (default) or `json`            |
| `--out <path>`    | Write to file instead of stdout      |

```bash
l4 export commitments --format csv > commitments.csv
l4 export commitments --provider gcp --format json --out commitments.json
```

The export walks every page, so it is the whole ledger rather than the first two hundred rows.

Columns differ by provider, because the two clouds expose different things: an AWS row carries the
expiry instant and what a renewal protects, a Google Cloud row carries neither. A Savings Plan's
coverage cell is empty rather than `0`, which is what a spreadsheet reads as no value. The reasons
are in [`l4 commitments`](/cli/commands/commitments#not-measured-is-not-zero).

## Archiving to object storage

Leave `--out` off and the export goes to stdout, so it can be piped straight into a bucket with no local file in between:

```bash
DATE=$(date -u +%Y-%m-%d)
l4 export costs --period 30d --format json | aws s3 cp - "s3://my-bucket/levelfour/costs-${DATE}.json"
```

## Related

* [Output formats](/cli/output-formats): `--csv`, `--json`, `--jq` and `--template` across every command
* [Recipes](/cli/recipes#monthly-csv-archive): the month-stamped costs CSV archive and the rest of the shell pipelines
* [`l4 costs`](/cli/commands/costs): the same cost data on screen, with filters and a TUI
* [`l4 recommendations`](/cli/commands/recommendations): the paginated list this exports in full
* [`/api-reference/costs`](/api-reference/costs) and [`/api-reference/recommendations`](/api-reference/recommendations): the underlying REST endpoints
