# l4 api

> Send an authenticated request to any LevelFour API endpoint, including the ones no dedicated subcommand wraps yet.

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


`l4 api` is the escape hatch: it sends an authenticated request to any LevelFour API endpoint without writing curl or composing headers yourself. It resolves a credential the same way every other `l4` command does. [CLI authentication](/cli/authentication) has that order.

```bash
l4 api <endpoint> [flags]
```

The endpoint must start with `/`, for example `/api/v1/costs/summary`.

> **Note**
>
> A read-only key fails on any endpoint that writes. [Key scopes](/authentication#key-scopes) has the split.

## Flags

| Flag                         | Description                                            |
| ---------------------------- | ------------------------------------------------------ |
| `-X` / `--method <verb>`     | HTTP method (default `GET`)                            |
| `-f` / `--field <key=value>` | Request body field (repeatable, used for POST)         |
| `--include`                  | Include the HTTP status line and headers in the output |

`l4 api` also takes the [global output flags](/cli/output-formats), including the `--jq` below.

## Examples

**GET an endpoint:**

```bash
l4 api /api/v1/costs/summary
```

**Filter the response with `--jq`:**

```bash
l4 api /api/v1/recommendations --jq '.data.items[0]'
```

**POST with body fields:**

```bash
l4 api -X POST /api/v1/api-keys -f name="CI Pipeline" -f scope=read
```

**Inspect the raw HTTP envelope:**

```bash
l4 api /api/v1/costs/summary --include
```

> **Success**
>
> A `2xx` on the status line is the proof: the request reached the endpoint and the credential was accepted.

## When to use the escape hatch

The [dedicated subcommands](/cli#command-groups) cover most workflows. They handle pagination, format the output for humans, and stay forwards-compatible.

Reach for `l4 api` when:

* No dedicated subcommand wraps the endpoint yet
* You want to script against the raw API envelope
* You are prototyping an integration before deciding whether to use an SDK

> **Tip**
>
> For language-native integrations, prefer the [SDKs](/sdks) over `l4 api`.

## Related

* [Output formats](/cli/output-formats): `--json`, `--jq`, `--template` and `--quiet`
* [CLI authentication](/cli/authentication): the credential order, and the key scopes `l4 api` inherits
* [API reference](/api-reference): every endpoint this command can reach
