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

> ## Agent Instructions
> Every Lath operation is POST https://platform.trylath.com/<operation name with dots replaced by slashes>, with a JSON body and `Authorization: Bearer <key>`. `email.send` is POST /email/send.
> Branch on `error.code`, never on `error.message`. Every refusal also carries `error.fix`, which names the next step.
> Send an `Idempotency-Key` header on any operation that is not retry-safe, so a retry cannot run it twice.
> A `lath_test_` key emails only the account's own members and sends no SMS; a `lath_live_` key reaches real recipients and is billed.
> The OpenAPI document, generated from the same registry as the routes, is at https://platform.trylath.com/openapi.json.

# CLI

> Every operation, from a terminal or a CI job. No subcommand is hand-written — the command list is generated from the same registry as the REST routes, so the CLI cannot be missing something the API has.

<Steps>
  <Step title="Run it">
    There is nothing to install for a one-off: `npx @trylath/cli` fetches and runs it. Installed, the binary is `lath`.

    With no arguments it prints the whole command list — every operation, with the sentence describing what it does.

    ```bash theme={null}
    npx @trylath/cli --help
    # or
    npm i -g @trylath/cli && lath --help
    ```
  </Step>

  <Step title="Store a key">
    `lath init` writes the key to `~/.lath/config.json` with mode `600`, so it is not passed on every command and does not land in your shell history.

    `LATH_API_KEY` overrides the file, which is what CI should use — an empty value counts as unset, because a template that exports `LATH_API_KEY=""` is more common than one that unsets it. `LATH_BASE_URL` and `LATH_CONFIG_DIR` override the rest.

    Without a key you get `no_key` and the fix, not a stack trace.

    ```bash theme={null}
    lath init --key lath_live_...

    # CI, or a shell you do not want to persist anything in
    LATH_API_KEY=lath_live_... lath email send --to you@example.com --subject Hi --text Hello
    ```
  </Step>

  <Step title="Call an operation">
    The shape is `lath <product> <name...>` with one flag per field. `--json` takes the whole input at once, which is easier to generate and easier to paste from the reference.

    A field the registry declares as an array is repeatable: pass the flag more than once.

    Anything not retry-safe takes `--idempotency-key`, and the CLI tells you which those are.

    ```bash theme={null}
    lath email send --to you@example.com --subject "Hello" --text "First one."

    # the same call, as one object
    lath email send --json '{"to":"you@example.com","subject":"Hello","text":"First one."}'

    # a write that must not double-send if the job is retried
    lath email send --json '{...}' --idempotency-key order-1043-receipt
    ```
  </Step>

  <Step title="Ask the CLI instead of the docs">
    `--help` on any command prints that operation's fields with their types, which are required, and any enum values — plus the three facts you need before calling it: whether it reads or writes, whether retrying is safe, and the permission the key must have.

    This is generated from the registry, so it is never out of date with the API in the way a written page can be.

    ```bash theme={null}
    $ lath email send --help
    lath email send

    Sends one transactional email to one recipient, from the project's default sender...

    mutation · not retry-safe: pass --idempotency-key · permission email:write

      --to                   string (required)  One recipient
      --template             string  A template name; provide variables with it
      --subject              string  Inline send: the subject
      --layout               string one of brand|none
    ```
  </Step>

  <Step title="Errors, and exit codes">
    A refusal prints the code and message on stderr, then the fix on its own line after an arrow. The exit code is non-zero, so a CI step fails rather than continuing quietly.

    The code is the same string the REST and MCP surfaces return, so a script can branch on it without parsing prose.

    ```bash theme={null}
    $ LATH_API_KEY= lath email send --to you@example.com --subject Hi --text Hello
    no_key: No API key is configured.
    → Run `lath init` and paste a key, or set LATH_API_KEY.
    ```
  </Step>

  <Step title="An MCP server for a local agent">
    `lath mcp` runs an MCP server over stdio, which is how you attach a local agent that does not speak HTTP MCP — it uses the key the CLI already has, so there is no second credential to configure.

    The hosted endpoint is the other option and needs no install: `POST https://platform.trylath.com/mcp`.

    ```json theme={null}
    {
      "mcpServers": {
        "lath": { "command": "npx", "args": ["-y", "@trylath/cli", "mcp"] }
      }
    }
    ```
  </Step>
</Steps>
