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

# Setup

> Install the Megan SDK, resolve your API key, and make your first call.

Megan ships inside the **`cadenza-cli` Python package**. The client is
standard-library only — it pulls in **no** third-party dependency and needs **no**
extras (`gym` / `lora` / `rl` / `vla`), so it's safe to add to a lightweight
project.

<Info>
  The standalone `cadenza` binary bundles its own Python and is **not importable**.
  To use the SDK from your own code, install the Python package into your project's
  environment.
</Info>

## 1. Install the package

```bash theme={null}
pip install cadenza-cli
# or, from a source checkout:
git clone https://github.com/aparekh02/cadenza.git
cd cadenza-cli && pip install -e .
```

Verify the import:

```bash theme={null}
python -c "from cadenza_cli import MeganTK; print('ok')"
```

## 2. Get a token

Your API key **is** your Cadenza sign-in token. If you don't have one, request one
by emailing **[acparekh@stanford.edu](mailto:acparekh@stanford.edu)**, then sign in
once so the CLI caches it:

```bash theme={null}
cadenza login <name> <token>
```

Print it back any time — with a ready-to-paste snippet — using `apikey`:

```bash theme={null}
cadenza apikey
# megan-tk API key  (= your sign-in token)
#   3Ls6••••••••••••QFvT
#   pass --reveal to print it in full
```

<Warning>
  Treat the token like a secret. `apikey` masks it by default; pass `--reveal` only
  when you need the full value, and prefer an environment variable over hard-coding
  it in source.
</Warning>

## 3. How the key is resolved

`MeganTK()` finds your key in this order — the first hit wins:

<Steps>
  <Step title="Explicit argument">
    `MeganTK(api_key="...")`
  </Step>

  <Step title="CADENZA_API_KEY">
    Environment variable — the recommended way to configure a deployed app.
  </Step>

  <Step title="CADENZA_TOKEN">
    Environment variable — accepted as an alias.
  </Step>

  <Step title="CLI session">
    `~/.cadenza/config.json` — so a machine that ran `cadenza login` just works.
  </Step>
</Steps>

If none resolve, the constructor raises `AuthRequired` with a message telling you
how to supply one.

```bash theme={null}
export CADENZA_API_KEY=<your-token>
```

```python theme={null}
from cadenza_cli import MeganTK

tk = MeganTK()          # reads CADENZA_API_KEY / CADENZA_TOKEN / CLI session
print(tk.version())     # {'service': 'megantk', 'megantk_version': '0.1.0', ...}
print(tk.ping())        # True if the token authenticates
```

## 4. Your first decision

```python theme={null}
from cadenza_cli import MeganTK

tk = MeganTK()

with tk.session(objective="pick up the red cube",
                milestones=["reach", "grasp", "lift"]) as s:
    # nothing reached yet, and a wall is blocking the first milestone
    d = s.step(reached=[], obstacles=[{"id": "wall", "milestone": 0}])
    print(d.route, "→", d.frontier)     # e.g. adapt → milestone_0

    d = s.step(reached=[0])             # cleared it
    print(d.route, "→", d.frontier)     # continue → milestone_1
```

## Configuration reference

| Setting         | How to set it                                                              | Default                           |
| --------------- | -------------------------------------------------------------------------- | --------------------------------- |
| **API key**     | `MeganTK(api_key=...)`, `CADENZA_API_KEY`, `CADENZA_TOKEN`, or CLI session | — (required)                      |
| **API URL**     | `MeganTK(api_url=...)` or `CADENZA_API_URL`                                | `https://www.api.cadenzalabs.xyz` |
| **Timeout (s)** | `MeganTK(timeout=...)`                                                     | `30.0`                            |

<Note>
  Point `CADENZA_API_URL` (or `api_url=`) at a locally-running Cadenza API for
  development. In production, leave it unset to use the hosted service.
</Note>

## Next

<CardGroup cols={2}>
  <Card title="Token sessions" icon="list-check" href="/megantk/sessions">
    The milestone and perception decision paths.
  </Card>

  <Card title="Usage & metering" icon="chart-line" href="/megantk/usage">
    See exactly what you've consumed.
  </Card>
</CardGroup>
