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

# AI Features

> Use Claude to explain, fix, suggest, review, and upgrade your infrastructure.

ubx has a suite of AI-powered commands built on Claude. All are opt-in, require your own Anthropic API key (BYOK), and degrade gracefully if the API is unavailable.

## Setup

<Steps>
  <Step title="Get an Anthropic API key">
    Sign up at [console.anthropic.com](https://console.anthropic.com).
  </Step>

  <Step title="Configure ubx">
    ```bash theme={null}
    export UBX_AI_API_KEY=sk-ant-...
    ```

    Or in `ubx.yaml`:

    ```yaml theme={null}
    ai:
      enabled: true
      api_key: "sk-ant-..."
      model: "claude-haiku-4-5"
      features:
        plan_summary: true
        cost_estimate: true
    ```
  </Step>

  <Step title="Verify">
    ```bash theme={null}
    ubx ai status
    ubx ai test
    # ✓ API key valid — claude-haiku-4-5 responding
    ```
  </Step>
</Steps>

## Commands

### `ubx explain`

```bash theme={null}
ubx explain                              # explain entire project
ubx explain main.iac                     # specific file
ubx explain unit.aws_rds_instance.db     # single resource
ubx explain --audience exec              # non-technical language
```

Produces: summary, resources, outputs, risks, next steps. See [`ubx explain`](/v1/cli/explain).

### `ubx fix`

```bash theme={null}
ubx fix                  # fix all errors
ubx fix main.iac         # fix specific file
ubx fix --dry-run        # show diff without applying
ubx fix --yes            # apply without confirmation
```

Runs `ubx validate`, sends errors + source to Claude, proposes fixes as a unified diff.

### `ubx suggest`

```bash theme={null}
ubx suggest "add a PostgreSQL RDS instance with 20GB storage"
ubx suggest "add an S3 bucket for logs" --append main.iac
ubx suggest "add EKS cluster" --dry-run
```

Reads existing `.iac` files for context, generates new blocks, appends after confirmation.

### `ubx review`

```bash theme={null}
ubx review                        # review entire project
ubx review --focus security       # security findings only
ubx review --focus cost           # cost findings only
ubx review --min-severity high    # critical and high only
```

Structured findings by severity. **Exit code 1** if any critical or high findings — safe for CI.

### `ubx upgrade`

```bash theme={null}
ubx upgrade --check          # exit 1 if any upgrades needed (CI mode)
ubx upgrade --dry-run        # show diff without applying
ubx upgrade --yes            # apply without confirmation
```

Two phases: mechanical mappings (instant) + AI suggestions (with API key).

Known mechanical mappings:

| Deprecated                 | Current                             |
| -------------------------- | ----------------------------------- |
| `aws_s3_bucket`            | `aws_s3_bucket_v2`                  |
| `aws_rds_cluster_instance` | `aws_rds_cluster`                   |
| `aws_elasticache_cluster`  | `aws_elasticache_replication_group` |
| `kubernetes_deployment`    | `kubernetes_deployment_v1`          |

## Plan Summary and Cost Estimate

When AI is enabled, `ubx plan` appends:

```
─── AI Summary ─────────────────────

This plan creates a PostgreSQL database and an S3 storage bucket.

Risk: medium — new database with hardcoded credentials

─── Cost Estimate ──────────────────

✓  Estimated monthly cost: ~$13.50  (high confidence)
RDS PostgreSQL db.t3.micro    $13.50
S3 bucket (assets)            $ 0.00
```

## Cost Limits

```hcl theme={null}
unit "aws_rds_instance" "db" {
  instance_class = "db.r6g.4xlarge"
  cost_limit     = 500   # $500/month maximum
}
```

```bash theme={null}
ubx validate --cost
# ✗  unit "db" estimated at $612/mo exceeds cost_limit of $500
```

## Privacy

* No telemetry. Data sent only to the Anthropic API.
* API key shown as last 4 chars only in `ubx ai status`.
* If key missing: all AI commands exit with a clear error.
