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

# CLI Guide

> Complete command-line interface reference for Galadriel

# CLI Guide

The Galadriel CLI is a command-line tool for interacting with the GPU marketplace. It provides a kubectl-style interface for managing orders, leases, and marketplace operations.

## Installation

<CodeGroup>
  ```bash macOS/Linux theme={null}
  curl -sSL https://galadriel.com/install.sh | sh
  ```

  ```bash Homebrew theme={null}
  brew install galadriel/tap/galadriel-cli
  ```

  ```bash Manual theme={null}
  wget https://github.com/galadriel-io/cli/releases/latest/download/galadriel-linux-amd64
  chmod +x galadriel-linux-amd64
  sudo mv galadriel-linux-amd64 /usr/local/bin/galadriel
  ```
</CodeGroup>

Verify installation:

```bash theme={null}
galadriel version
```

## Configuration

### Initial Setup

```bash theme={null}
galadriel configure
```

You'll be prompted for:

* API token (get from [https://app.galadriel.com/settings/tokens](https://app.galadriel.com/settings/tokens))
* Default zone (e.g., `us-west-1`)
* SSH public key (optional)

Configuration is saved to `~/.galadriel/config.yaml`:

```yaml theme={null}
api_token: gal_abc123...
default_zone: us-west-1
ssh_public_key: ssh-ed25519 AAAAC3...
```

### Environment Variables

Override config with environment variables:

```bash theme={null}
export GALADRIEL_TOKEN=gal_abc123...
export GALADRIEL_ZONE=us-west-1
```

## Marketplace Commands

### Create Buy Order

#### Market Order (Instant)

```bash theme={null}
galadriel order buy \
  --gpu-type h100 \
  --gpus 16 \
  --duration 24h \
  --zone us-west-1 \
  --type market
```

**Options:**

* `--gpu-type` - GPU type: `h100`, `h200`, `b200`, `b300`
* `--gpus` - Number of GPUs (multiple of 8)
* `--duration` - Duration: `12h`, `24h`, `7d`, etc.
* `--zone` - Availability zone
* `--type` - Order type (default: `market`)

#### Limit Order (Wait for Price)

```bash theme={null}
galadriel order buy \
  --gpu-type h100 \
  --gpus 16 \
  --duration 24h \
  --price 3.20 \
  --zone us-west-1
```

**Additional Options:**

* `--price` - Maximum price per GPU/hour
* `--start` - Start time (ISO 8601, default: now)

#### Flexible Order (Best Price)

```bash theme={null}
galadriel order buy \
  --gpu-type h100 \
  --gpus 8 \
  --duration 12h \
  --price 3.00 \
  --flex 48h \
  --zone us-west-1
```

**Additional Options:**

* `--flex` - Time window for execution

### List Orders

```bash theme={null}
# All active orders
galadriel order list

# Filter by status
galadriel order list --status pending
galadriel order list --status filled

# Filter by side
galadriel order list --side buy
galadriel order list --side sell
```

**Output:**

```
ORDER ID     TYPE    SIDE  GPUs  STATUS   PRICE    FILLED  CREATED
ord_abc123   market  buy   16    filled   -        16/16   2h ago
ord_def456   limit   buy   16    pending  $3.20    0/16    30m ago
ord_ghi789   limit   sell  8     pending  $3.80    0/8     1h ago
```

### Get Order Status

```bash theme={null}
galadriel order get ord_abc123
```

**Output:**

```
ORDER ID:     ord_abc123
TYPE:         limit
SIDE:         buy
GPU TYPE:     h100
GPU COUNT:    16
LIMIT PRICE:  $3.50/hr
STATUS:       partial
FILLED:       8/16 GPUs (50%)
AVG PRICE:    $3.45/hr
CREATED:      2h ago
EXPIRES:      in 2h

MATCHES:
  - 8 GPUs @ $3.45/hr (matched 1h ago)
    Lease: lse_xyz123
```

### Cancel Order

```bash theme={null}
# Cancel entire order
galadriel order cancel ord_abc123

# Cancel with confirmation
galadriel order cancel ord_abc123 --yes
```

## Orderbook Commands

### View Orderbook

```bash theme={null}
galadriel orderbook --gpu-type h100 --zone us-west-1
```

**Output:**

```
📊 Orderbook: H100 @ us-west-1 (2025-11-11 14:00 UTC)

Market Depth:
  Best Bid:  $1.30/GPU/hr  (24 GPUs)
  Best Ask:  $1.40/GPU/hr  (16 GPUs)
  Spread:    $0.10 (7.69%)
  Mid Price: $1.35

Bids (Buy Orders):                     Asks (Sell Orders):
  $1.30 ████████████████ 24 GPUs        $1.40 ████████ 16 GPUs
  $1.25 ███████████ 16 GPUs             $1.45 ████ 8 GPUs
  $1.20 ███████████████████ 32 GPUs     $1.50 ████████████ 24 GPUs

Last Trade: $1.35 (8 GPUs) @ 13:55 UTC
24h Volume: 1,920 GPU-hours
```

**Options:**

* `--gpu-type` - GPU type
* `--zone` - Availability zone
* `--depth` - Number of price levels (default: 10)

### View Prices

```bash theme={null}
# Historical prices
galadriel prices --gpu-type h100 --zone us-west-1 --days 7

# Custom time range
galadriel prices \
  --gpu-type h100 \
  --zone us-west-1 \
  --start "2025-11-01T00:00:00Z" \
  --end "2025-11-07T23:59:59Z"

# With interval
galadriel prices --gpu-type h100 --zone us-west-1 --interval 1h
```

### Get Price Estimate

```bash theme={null}
galadriel prices estimate \
  --gpu-type h100 \
  --gpus 16 \
  --zone us-west-1
```

**Output:**

```
Price Estimate for Market Order
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
GPU Type: H100
Zone: us-west-1
Quantity: 16 GPUs

Estimated price: $1.38/hr (weighted average)
Best ask: $1.40/hr
Worst fill price: $1.45/hr
Total available: 48 GPUs
Sufficient liquidity: YES ✓

For 24h lease:
  Estimated cost: $530.88
  Platform fee: $53.09
  Total: $583.97
```

## Lease Management

### List Leases

```bash theme={null}
# All active leases
galadriel list

# Filter by status
galadriel list --status all
galadriel list --status active
galadriel list --status expired
```

**Output:**

```
LEASE ID    GPUs  GPU TYPE  ZONE       STATUS  EXPIRES             COST/HR
lse_xyz123  16    H100      us-west-1  active  2025-11-12 14:00   $3.70
lse_abc456  8     H100      us-east-1  active  2025-11-07 10:00   $3.50
```

### Get Lease Details

```bash theme={null}
galadriel get lse_xyz123
```

**Output:**

```
LEASE ID:       lse_xyz123
CUSTOMER ID:    alice
GPU TYPE:       h100
GPU COUNT:      16
INSTANCE TYPE:  16xh100
NODES:          gpu-node-042, gpu-node-043
ZONE:           us-west-1
STATUS:         active
NAMESPACE:      customer-alice-lse-xyz123

TIMING:
  Start:        2025-11-11 14:00 UTC
  End:          2025-11-12 14:00 UTC
  Duration:     24h
  Remaining:    18h 30m

COST:
  Rate:         $1.40/GPU/hr
  Total cost:   $1,420.80
  Spent so far: $324.40
  Remaining:    $1,096.40

SSH ACCESS:
  customer@gpu-node-042.galadriel.com:22
  customer@gpu-node-043.galadriel.com:22

KUBECONFIG:
  ~/.kube/galadriel-lse-xyz123.conf
```

### Get Kubeconfig

```bash theme={null}
# Print to stdout
galadriel kubeconfig lse_xyz123

# Save to file
galadriel kubeconfig lse_xyz123 --save ~/.kube/galadriel.conf

# Set as current context
galadriel kubeconfig lse_xyz123 --set
```

### SSH Access

```bash theme={null}
# SSH to first node
galadriel ssh lse_xyz123

# SSH to specific node
galadriel ssh lse_xyz123 --node gpu-node-042

# SSH with custom command
galadriel ssh lse_xyz123 -- nvidia-smi
```

### Resell Lease

```bash theme={null}
# Basic resell
galadriel lease resell lse_xyz123 --price 3.00

# With transfer time
galadriel lease resell lse_xyz123 \
  --price 3.00 \
  --from "2025-11-12T14:00:00Z"

# Transfer immediately
galadriel lease resell lse_xyz123 \
  --price 3.00 \
  --transfer-now
```

**Output:**

```
💰 Creating resell order for unused GPU time...
✓ Order ID: ord_resell123
✓ Lease: lse_xyz123 (16x H100 GPUs)
✓ Original price: $3.45/GPU/hr
✓ Resell price: $1.20/GPU/hr
✓ Time remaining: 48 hours
✓ Potential recovery: $2,304.00
✓ After 10% platform fee: $1,958.40
```

### Terminate Lease

```bash theme={null}
# Terminate with confirmation
galadriel terminate lse_xyz123

# Skip confirmation
galadriel terminate lse_xyz123 --yes
```

## Inventory Commands

### View Inventory

```bash theme={null}
# All zones
galadriel inventory

# Specific zone
galadriel inventory --zone us-west-1

# Specific GPU type
galadriel inventory --gpu-type h100
```

**Output:**

```
GPU Inventory
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

us-west-1:
  H100:  800 GPUs (100 nodes) available
  H200:  240 GPUs (30 nodes) available
  B200:  160 GPUs (20 nodes) available
  B300:   80 GPUs (10 nodes) available

us-east-1:
  H100:  640 GPUs (80 nodes) available
  H200:  192 GPUs (24 nodes) available
  B200:  128 GPUs (16 nodes) available
  B300:   64 GPUs (8 nodes) available

eu-west-1:
  H100:  480 GPUs (60 nodes) available
  H200:  144 GPUs (18 nodes) available
  B200:   64 GPUs (8 nodes) available
  B300:    8 GPUs (1 node) available

Total: 3,000 GPUs across all zones
```

## Billing Commands

### View Usage

```bash theme={null}
# Current billing period
galadriel billing usage

# Previous period
galadriel billing usage --period previous
```

**Output:**

```
Billing Period: November 2025
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Current Charges: $7,139.66

Active Leases:
  lse_xyz123: 384 GPU-hours @ $3.70/hr = $1,689.60
  lse_abc456: 192 GPU-hours @ $3.50/hr = $  806.40

Payment Method: Card ending in 1234
Due Date: 2025-12-08
```

### View Invoices

```bash theme={null}
# Recent invoices
galadriel billing invoices

# With limit
galadriel billing invoices --limit 10
```

## Global Options

All commands support these global flags:

```bash theme={null}
--token string      API token (overrides config)
--zone string       Default availability zone
--output string     Output format: text, json, yaml
--verbose          Enable verbose output
--quiet            Suppress all output except errors
--yes              Skip confirmations
```

### Examples

```bash theme={null}
# JSON output
galadriel list --output json

# Different token
galadriel order list --token gal_different_token

# Quiet mode
galadriel terminate lse_xyz123 --yes --quiet
```

## Bash Completion

### Setup

```bash theme={null}
# Bash
galadriel completion bash > /etc/bash_completion.d/galadriel

# Zsh
galadriel completion zsh > "${fpath[1]}/_galadriel"

# Fish
galadriel completion fish > ~/.config/fish/completions/galadriel.fish
```

### Usage

After setup, tab completion works:

```bash theme={null}
galadriel or<TAB>     # Completes to "galadriel order"
galadriel order <TAB>  # Shows: buy, sell, list, get, cancel
```

## Advanced Usage

### Piping and Scripting

```bash theme={null}
# Get all pending order IDs
galadriel order list --status pending --output json | jq -r '.orders[].order_id'

# Cancel all pending orders
for id in $(galadriel order list --status pending --output json | jq -r '.orders[].order_id'); do
  galadriel order cancel $id --yes
done

# Export kubeconfigs for all leases
for lease in $(galadriel list --output json | jq -r '.leases[].lease_id'); do
  galadriel kubeconfig $lease --save ~/.kube/$lease.conf
done
```

### Watch Mode

```bash theme={null}
# Watch orders
watch -n 5 'galadriel order list'

# Watch orderbook
watch -n 10 'galadriel orderbook --gpu-type h100 --zone us-west-1'

# Watch leases
watch -n 30 'galadriel list'
```

### Aliases

Add to your `~/.bashrc` or `~/.zshrc`:

```bash theme={null}
alias gb='galadriel order buy'
alias gl='galadriel list'
alias gk='galadriel kubeconfig'
alias gs='galadriel ssh'
alias go='galadriel orderbook'
```

## Troubleshooting

### Common Issues

<AccordionGroup>
  <Accordion title="Command not found">
    Ensure the CLI is in your PATH:

    ```bash theme={null}
    which galadriel
    ```

    If not found, add to PATH:

    ```bash theme={null}
    export PATH=$PATH:/usr/local/bin
    ```
  </Accordion>

  <Accordion title="Authentication failed">
    Check your API token:

    ```bash theme={null}
    cat ~/.galadriel/config.yaml | grep api_token
    ```

    Reconfigure if needed:

    ```bash theme={null}
    galadriel configure
    ```
  </Accordion>

  <Accordion title="Order not filling">
    Check the orderbook to see if your price is competitive:

    ```bash theme={null}
    galadriel orderbook --gpu-type h100 --zone us-west-1
    ```

    Cancel and retry with better price or use market order.
  </Accordion>
</AccordionGroup>

### Debug Mode

Enable verbose logging:

```bash theme={null}
galadriel --verbose order list
```

## Next Steps

<CardGroup cols={2}>
  <Card title="API Reference" icon="code" href="/api-reference">
    REST API documentation
  </Card>

  <Card title="SDK Guide" icon="book-open" href="/sdk-guide">
    Python and TypeScript SDKs
  </Card>

  <Card title="Examples" icon="lightbulb" href="/examples">
    Real-world usage examples
  </Card>

  <Card title="Quickstart" icon="rocket" href="/quickstart">
    Get started in 5 minutes
  </Card>
</CardGroup>
